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

recycled query teardown #740

Merged
merged 6 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#### BREAKING FOR TYPESCRIPT USERS
- Feature: Enhanced typescript definitions to allow for more valid type checking of graphql HOC [PR #695](https://github.com/apollographql/react-apollo/pull/695)
- Feature: Flow types: [PR #695](https://github.com/apollographql/react-apollo/pull/695)

- Fix: Fix bug with sync re-renders and recyled queries [PR #740](https://github.com/apollographql/react-apollo/pull/740)

### 1.3.0
- Feature: Support tree shaking and smaller (marginally) bundles via rollup [PR #691](https://github.com/apollographql/react-apollo/pull/691)
Expand Down
10 changes: 7 additions & 3 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,18 @@ export default function graphql<TResult = {}, TProps = {}, TChildProps = Default

componentWillUnmount() {
if (this.type === DocumentType.Query) {
// It is critical that this happens prior to recyling the query
// if not it breaks the loading state / network status because
// an orphan observer is created in AC (intended) which is cleaned up
// when the browser has time via a setTimeout(0)
// Unsubscribe from our query subscription.
this.unsubscribeFromQuery();

// Recycle the query observable if there ever was one.
if (this.queryObservable) {
recycler.recycle(this.queryObservable);
delete this.queryObservable;
}

// Unsubscribe from our query subscription.
this.unsubscribeFromQuery();
}

if (this.type === DocumentType.Subscription) this.unsubscribeFromQuery();
Expand Down