-
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
Queries in a re-mounted component revert to using "fetchPolicy" instead of "nextFetchPolicy" #7311
Comments
Hi, I have a question about this proposal. I have a paginated query which should be refetched every time the component mounts. Currently, I am doing this with |
@dylanwulf the way I have it instrumented, it's opt-in behavior. It's configurable under |
@dannycochran ah ok that sounds good, thank you for the quick response! |
It appears this has been addressed in the linked issues. Please feel free to ping me if you feel this should be re-opened. Thanks all! |
Intended outcome:
I would like to avoid queries re-firing when returning to a previously mounted component, since the query has already fired once and has the data in cache.
I would expect that after the first query completes in the browser lifecycle, "nextFetchPolicy" is used thereafter in that query until the user re-loads the page.
Actual outcome:
I use the default settings from above.
Queries that fired within a component use
cache-and-network
to start, but once the component is unmounted (via a route change), and then returned to,cache-and-network
is used again instead ofcache-first
.This results in the query re-firing, even though the data is already available in cache.
How to reproduce the issue:
Minimal reproduction repository and instructions can be found here:
https://github.com/dannycochran/usequery
git clone https://github.com/dannycochran/usequery cd usequery npm install npm run start
Versions
System:
OS: macOS 10.15.6
Binaries:
Node: 12.18.4 - /usr/local/bin/node
Yarn: 1.22.4 - ~/npm-global/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Browsers:
Chrome: 86.0.4240.193
Safari: 14.0
npmPackages:
@apollo/client: ^3.2.5 => 3.2.5
apollo-server-express: ^2.19.0 => 2.19.0
npmGlobalPackages:
apollo: 2.27.0
Disclaimer
If this bug is in fact intended behavior, I'd like to discuss what a good work around is for the behavior I want. Currently I'm wrapping
useQuery
and doing this hacky workaround which uses the query as stringified JSON to keep track of whether the query has already fired once.The text was updated successfully, but these errors were encountered: