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

v2.5.0+ re-render prevented on loading change in Query component #2887

Closed
YoonjiJang opened this issue Mar 20, 2019 · 0 comments · Fixed by #2840
Closed

v2.5.0+ re-render prevented on loading change in Query component #2887

YoonjiJang opened this issue Mar 20, 2019 · 0 comments · Fixed by #2840
Assignees

Comments

@YoonjiJang
Copy link

Intended outcome:
I have a list of items that displays data from Query component and a modal form that opens up and calls refetch from the aforementioned Query component when the form is submitted. After network request from refetch has been completed, the component should re-render itself to pass the updated loading/networkStatus values to the render prop, even if the data returned from the server is the same as the data in local cache.

Actual outcome:
After network request from calling refetch has been completed, the queryObservable's next handler gets called, but second if block (https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L335-L342)
prevents the component from re-rendering.

How to reproduce the issue:

https://stackblitz.com/edit/react-bv7rtg?file=index.js
Please follow the link to see how to reproduce a simplified version of my current situation. It seems that when I toggle open state in App component (equivalent to opening a modal form), the lastResult variable in Query component (defined here https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L126) is set to the last query result which looks something like

{
  loading: false,
  networkStatus: 7,
  data: { ... }
}

and when the refetch request is done, the query result that gets passed to the queryObservable's next handler (https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L327-L346) is

{
  loading: false,
  networkStatus: 7,
  data: { ...(same as before) }
}

This satisfies the second if block (https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L335-L342) so updateCurrentData doesn't get called and the Query component is not re-rendered.

Version

@hwillson hwillson self-assigned this Mar 20, 2019
hwillson added a commit to astrid-tech/react-apollo that referenced this issue Mar 20, 2019
hwillson pushed a commit that referenced this issue Mar 20, 2019
#2840)

* Update lastResult whenever data changes to ensure components re-render if result is set back to original lastResult

* Add a regression test to verify this is fixed

Base on the reproduction provided in #2887.

* Changelog update
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants