Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Fix crash in unsubscribeFromQuery
Browse files Browse the repository at this point in the history
Also delete querySubscription when there is no subscription, since that
seems reasonable.

See #255.
  • Loading branch information
glasser committed Oct 11, 2016
1 parent 6baf0fd commit 1036a23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Expect active development and potentially significant breaking changes in the `0

### vNext

- Bug: Fix possible crash in unsubscribeFromQuery [#260](https://github.com/apollostack/react-apollo/pull/260)

### v0.5.8

- Feature: Remove nested imports for apollo-client. Making local development eaiser. [#234](https://github.com/apollostack/react-apollo/pull/234)
Expand Down
17 changes: 11 additions & 6 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,13 @@ export default function graphql(
}

componentWillReceiveProps(nextProps) {
// if this has changed, remove data and unsubscribeFromQuery
if (!mapPropsToSkip(this.props) && mapPropsToSkip(nextProps)) {
delete this.data;
return this.unsubscribeFromQuery();
if (mapPropsToSkip(nextProps)) {
if (!mapPropsToSkip(this.props)) {
// if this has changed, remove data and unsubscribeFromQuery
delete this.data;
this.unsubscribeFromQuery();
}
return;
}
if (shallowEqual(this.props, nextProps)) return;

Expand Down Expand Up @@ -354,7 +357,7 @@ export default function graphql(
if (this.querySubscription) {
this.hasOperationDataChanged = true;
this.data = { loading: false };
this.querySubscription.unsubscribe();
this.unsubscribeFromQuery();
this.forceRenderChildren();
}
return;
Expand Down Expand Up @@ -416,9 +419,11 @@ export default function graphql(
}

unsubscribeFromQuery() {
if ((this.querySubscription as Subscription).unsubscribe) {
if (this.querySubscription &&
(this.querySubscription as Subscription).unsubscribe) {
(this.querySubscription as Subscription).unsubscribe();
delete this.queryObservable;
delete this.querySubscription;
}
}

Expand Down

0 comments on commit 1036a23

Please sign in to comment.