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

Queries cancelled in strict mode with nextFetchPolicy: "cache-first" #9989

Closed
markedwards opened this issue Aug 6, 2022 · 8 comments · Fixed by #10630
Closed

Queries cancelled in strict mode with nextFetchPolicy: "cache-first" #9989

markedwards opened this issue Aug 6, 2022 · 8 comments · Fixed by #10630

Comments

@markedwards
Copy link

Intended outcome:

  1. Configure a component to use useQuery with fetchPolicy: "network-only" or fetchPolicy: "cache-and-network", and nextFetchPolicy: "cache-first".
  2. Mount the component, query is made.
  3. Unmount the component.
  4. Mount the component a second time, query should be made.

Actual outcome:

In step 4, the query happens, but is immediately cancelled. So, a query with a given set of variables will only be made once, and can never be made again. This only happens in React strict mode, the behavior is as-expected with React strict mode off.

How to reproduce the issue:

https://codesandbox.io/s/distracted-babbage-ry92hc?file=/src/index.jsx

Toggle mount/unmount with strict mode on, observe cancelled queries. With strict mode off, queries are not cancelled.

Versions

System:
OS: Linux 4.14 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
Binaries:
Node: 16.15.0 - /usr/bin/node
Yarn: 1.22.18 - /usr/bin/yarn
npm: 8.5.5 - /usr/bin/npm
npmPackages:
@apollo/client: ^3.6.9 => 3.6.9

@adrienharnay
Copy link

Also facing this, which makes StrictMode impossible to use 😞 I see there is a reproduction, has work on this been planned? Thanks in advance and have a great day!

@adrienharnay
Copy link

Hello @hwillson, could you please take a look at this and point us in the right direction? Thanks a lot 🙏

@SimenB
Copy link
Contributor

SimenB commented Mar 29, 2023

@benjamn @jerelmiller is this something you could take a look at? The reproduction is short and sweet (and it still reproduces on 3.7.10)

@SimenB
Copy link
Contributor

SimenB commented Mar 29, 2023

Hmm, that said, it does not reproduce using the alpha (currently 3.8.0-alpha.11).

Using the alpha in my own project also resolves the issue.

@phryneas
Copy link
Member

Yeah, I would presume that this was fixed with #10629. I wanted to create you a PR build to test it, but it seems that the GitHub action is broken right now.

Either way, we will probably release a new version within the next few days, and this should be included there.

@phryneas
Copy link
Member

Ah, got it to build with a tip from @alessbell.
It seems to fix the reproduction - can you try it in your codebase please?

npm i @apollo/client@0.0.0-pr-10629-20230329120619

@SimenB
Copy link
Contributor

SimenB commented Mar 30, 2023

@phryneas yeah, can confirm installing that version specifically also fixes our tests 👍

@phryneas phryneas linked a pull request Mar 30, 2023 that will close this issue
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2023
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.

5 participants