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

Query not being cleaned up when on Strict Mode #8011

Closed
PierreAndreis opened this issue Apr 20, 2021 · 7 comments
Closed

Query not being cleaned up when on Strict Mode #8011

PierreAndreis opened this issue Apr 20, 2021 · 7 comments

Comments

@PierreAndreis
Copy link

PierreAndreis commented Apr 20, 2021

Intended outcome:
When unmounting a component that uses useQuery, it should clean up even when wrapped by Strict Mode.

Actual outcome:
Updating the cache on which an unmount component depends, generates a react warning about memory leak.

How to reproduce the issue:
https://codesandbox.io/s/nifty-heyrovsky-5cf34
1- Click on "John Smith" and wait for the page to load
2- Click on "Back"
3- Click on "Like" button right by "John Smith"
4- Observe the warning in the console.

Checking on Apollo DevTools, there seems to be more active queries than it should have been after a few times reproducing the issue.
image
Compared to when Strict mode is not active:
image
Versions

@apollo/client: 3.3.15
graphql: 15.4.0
react: 17.0.2
react-dom: 17.0.2
react-router-dom: 5.2.0
@PierreAndreis
Copy link
Author

Note that this doesn't happen in production build, when strict mode is noop.

@PierreAndreis
Copy link
Author

Might be related to #7952 (comment)

@bmviniciuss
Copy link

bmviniciuss commented May 13, 2021

Having the same issue on Strict mode and getting the 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 error.

"dependencies": {
    "@apollo/client": "^3.3.17",
    "graphql": "^15.5.0",
    "react": "^17.0.0",
    "react-dom": "^17.0.0",
    "react-router-dom": "^5.2.0",
    "typescript": "^4.1.2",
    "vite": "^2.3.0"
  }

image
image

@6axter82
Copy link

Having this warnings in "@apollo/client": "^3.3.19"

@hwillson
Copy link
Member

hwillson commented Aug 3, 2021

This should be fixed with @apollo/client >= 3.4 - thanks!

@hwillson hwillson closed this as completed Aug 3, 2021
@Ralino
Copy link

Ralino commented Aug 18, 2021

While the warning is gone, I still have the issue that the queries are not cleaned up with @apollo/client 3.4.8 when strict mode is enabled, as shown in this demo: https://codesandbox.io/s/nostalgic-solomon-4stu5

Looking at the active queries with the dev tools, it seems like a query is spawned twice, one with "__typename" queried as well and one without. But only the query with "__typename" is cleaned up. Without strict mode, only a query with "__typename" is spawned (and cleaned up).

@hjrobinson
Copy link

I just wanted to note here for anyone using react-router's history to navigate to another page after deleting a document that the memory leak warning went away when I updated to the latest version of @apollo/client (for me this was "@apollo/client": "^3.5.10"). I was previously using version 3.1.4. I needed to restart my application for this to take effect.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants