Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore option callbacks when deciding to update a query #6588

Merged
merged 4 commits into from
Jul 20, 2020
Merged

Conversation

hwillson
Copy link
Member

QueryData stores last used options to help decide when it should re-run. If new options (when compared against the previously stored last options) are found, QueryData will make sure the new options are passed into Apollo Client for processing. When onCompleted and/or onError options are set however, QueryData thinks the options received on each render are new as these callback functions don't have a stable identity. This can then lead to infinite re-renders.

This commit adjusts the QueryData option equality check to ignore option callbacks. During normal use of useQuery it should be okay to ignore callbacks like this, as they don't normally change between renders.

Fixes #6301

src/react/data/QueryData.ts Outdated Show resolved Hide resolved
@hwillson
Copy link
Member Author

Thanks for the @wry/equality changes @benjamn - definitely a better approach! 🎉

hwillson and others added 4 commits July 20, 2020 15:56
`QueryData` stores last used options to help decide when it should
re-run. If new options (when compared against the previously
stored last options) are found, `QueryData` will make sure the
new options are passed into Apollo Client for processing.
When `onCompleted` and/or `onError` options are set however,
`QueryData` thinks the options received on each render are new
as these callback functions don't have a stable identity. This
can then lead to infinite re-renders.

This commit adjusts the `QueryData` option equality check to
ignore option callbacks. During normal use of `useQuery` it
should be okay to ignore callbacks like this, as they don't
normally change between renders.

Fixes #6301
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not memoize onCompleted and onError never resolves the query
2 participants