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

fix: address React StrictMode error when query resolves after unmount #6216

Merged
merged 2 commits into from
Jun 2, 2020
Merged

fix: address React StrictMode error when query resolves after unmount #6216

merged 2 commits into from
Jun 2, 2020

Conversation

grxy
Copy link
Contributor

@grxy grxy commented Apr 29, 2020

Motivation

useQuery can log a warning in React's StrictMode when a component is unmounted before the query has been resolved.

Changes

  • Adds a failing test to demonstrate the issue
  • Checks if a component is mounted before running the forceUpdate function

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

Resolves apollographql/react-apollo#3635

@apollo-cla
Copy link

@grxy: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@grxy grxy marked this pull request as ready for review April 29, 2020 20:45
@benjamn
Copy link
Member

benjamn commented May 8, 2020

@grxy Would you mind rebasing?

@nodabladam
Copy link

I believe I am experiencing the same problem. It would be great to get this into apollo 3

@rajohan
Copy link

rajohan commented May 25, 2020

Got the same problem, tried your solution by manually making the changes in the node_modules folder and it fixes it. Would be nice to get this added.

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and thanks for rebasing @grxy!

@joonhocho
Copy link

joonhocho commented Jun 4, 2020

This seems to break SSR. #6386 . Just spent a good amount of time tracking down the bug, and this makes an app to hang indefinitely.

benjamn added a commit that referenced this pull request Jun 4, 2020
PR #6216 introduced these isMounted guards, and was merged just before the
v3.0.0-rc.0 release. It appears (see #6386) that requiring the component
to be mounted is too restrictive, specifically when doing server-side
rendering, since the concept of mounting doesn't make sense without a DOM.
benjamn added a commit that referenced this pull request Jun 4, 2020
PR #6216 introduced these isMounted guards, and was merged just before the
v3.0.0-rc.0 release. It appears (see #6386) that requiring the component
to be mounted is too restrictive, specifically when doing server-side
rendering, since the concept of mounting doesn't make sense without a DOM.
benjamn added a commit that referenced this pull request Jun 5, 2020
This reverts commits b6da9c8 (#6388) and
c76804e (#6216).

Preventing StrictMode warnings in React is not worth introducing bugs that
break applications. We will need to reconsider how best to prevent
warnings for unmounted components.
benjamn added a commit that referenced this pull request Jun 5, 2020
This reverts commits b6da9c8 (#6388) and
c76804e (#6216).

Preventing StrictMode warnings in React is not worth introducing bugs that
break applications. We will need to reconsider how best to prevent
warnings for unmounted components.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useQuery causes warning in strict mode
6 participants