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

Commit

Permalink
Reorder code to avoid setting state on unmounted component (#3139)
Browse files Browse the repository at this point in the history
* Move setState earlier.

This solves the problem of the component being unmounted as a result
of onSubscriptionData, then setState causing a React warning. See #2681.

* Changelog update
  • Loading branch information
jasonpaulos authored and hwillson committed Jun 21, 2019
1 parent a1e0b6d commit dca8f7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
responses couldn't be handled). The `Query` component can now handle an
error in a response, then continue to handle a valid response afterwards. <br/>
[@hwillson](https://github.com/hwillson) in [#3107](https://github.com/apollographql/react-apollo/pull/3107)
- Reorder `Subscription` component code to avoid setting state on unmounted
component. <br/>
[@jasonpaulos](https://github.com/jasonpaulos) in [#3139](https://github.com/apollographql/react-apollo/pull/3139)


## 2.5.6 (2019-05-22)
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ class Subscription<TData = any, TVariables = any> extends React.Component<
client,
props: { onSubscriptionData },
} = this;
if (onSubscriptionData) onSubscriptionData({ client, subscriptionData: result });
this.setState({
data: result.data,
loading: false,
error: undefined,
});
if (onSubscriptionData) onSubscriptionData({ client, subscriptionData: result });
};

private updateError = (error: any) => {
Expand Down

0 comments on commit dca8f7a

Please sign in to comment.