-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Warning: Can't perform a React state update on an unmounted component. #6209
Comments
I found the cause. The issue is because of <React.StrictMode> apollographql/react-apollo#3635 |
@amiyatulu is this still happening when you use the latest |
Yes, it's still given the error after upgrade to 3.0.0-beta.50 |
Is this the fix and if so can it get merged? |
Still happening for me with Edit: Oh well, just saw #6395 (comment) that talks about #6216's revert |
Error seems to be gone for me on |
I'm still seeing this error when using
My I'm using StrictMode and on Happy to provide more details if needed! |
- note that this currently causes the following warning whenever a game is completed, as it causes the `GetRecentlyCompleted` query to be revaluated even though the component isn't currently visible, and mounted ``` Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. in RecentlyCompleted (at Start.js:145) in Start (at App.js:48) ``` this is a known issue in Apollo, which as of writing is still being worked on: apollographql/apollo-client#6209
I have been tracking this warning for a while and I can confirm that useQuery is the source of the warning. The warning says 'Warning: Can't perform a React state update on an unmounted component'. I am using:
It is happening mostly in a page where the component is un-mounting . useQuery is reading from cache. Hope this help fix the problem. |
I wasn't sure if my similar issue (more like #6248) is a bug or not so I posted it with more details on SO https://stackoverflow.com/questions/62938649/react-apollo-client-arning-cant-perform-a-react-state-update-on-an-unmounted |
Happened also when route changes while current route has a useQuery |
@Felix-Indoing same for me 😕 |
Same here |
Every time I get "state update on an unmounted component" in the console, this issue makes it hard to tell if it is really due to state in my code or not and if I have actually fixed legitimate issues because this issue causes so many errors. If there is a way to fix this without breaking SSR, it would really help. |
same here |
I got the same issue when the route changes with "@apollo/react-hooks": "^3.1.5" |
I was struggling with a similar issue an solved it by using import { useEffect } from "react";
import { useLazyQuery } from "@apollo/client";
// ...
const [myQueryExecutor, { data }] = useLazyQuery(MY_QUERY);
// execute query on component mount
useEffect(
() => { myQueryExecutor(); },
[myQueryExecutor]
); |
I got the same issue as well with |
same here |
Still actual!! |
still failing. |
Still the same warnings :( |
Same. |
That seemed to do the trick, thanks @davidgilbertson! |
unfortunately it changed nothing for me, still getting this error |
I also tried wrapping ApolloProvider inside BrowserRouter in index.ts (before I had BrowserRouter wrapping my routes in App.js) and I am still getting the error: ` ReactDOM.render(
); I have also tried swapping Router and ApolloProvider in the code above and I still get the warning. I can confirm though that using useLazyQuery + useEffect gets rid of the warning. Not sure if this is intended or ideal. |
• replaced useQuery with useLazyQuery + useEffect in Library • apollographql/apollo-client#6209 (comment)
It might be related to #8011 |
Is there any update regarding this? Still the same warning when using |
it's still an issue so only solution now is lazy query and useEffect? |
@jgwiazdowski The best workaround so far (in my opinion) is to use a hook telling you whether a component is mounted or not and to pass that Boolean to the |
useLazyQuery and useEffect does not work for me sadly. Any movement on this? |
i have encountered same problem. I tried every possibility. This is the solution that help me with. Using skip { skip:true } after getting data solves
|
This issue is related to StrictMode, and I have a working reproduction on #8011 |
|
This should be fixed with @apollo/client >= 3.4 - thanks! |
This is the code for useMuation
But on using refetchQueries it gives the following warning
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
This is my nav code:
And the is MeQuery()
The text was updated successfully, but these errors were encountered: