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

requestPolicy: cache-and-network is ignored in urql v3 #2631

Closed
3 tasks done
fathyb opened this issue Aug 21, 2022 · 1 comment · Fixed by #2634
Closed
3 tasks done

requestPolicy: cache-and-network is ignored in urql v3 #2631

fathyb opened this issue Aug 21, 2022 · 1 comment · Fixed by #2634

Comments

@fathyb
Copy link
Contributor

fathyb commented Aug 21, 2022

Describe the bug

urql v3 differs from v2 when using requestPolicy: cache-and-network as documented:

The cache-and-network policy is particularly useful, since it allows us to display data instantly if it has been cached, but also refreshes data in our cache in the background. This means though that fetching will be false for cached results although an API request may still be ongoing in the background.

In the repro, urql v2 correctly performs a request every time Todos is displayed after toggling, whereas urql v3 doesn't.

Reproduction

https://codesandbox.io/s/async-flower-cspnze?file=/src/index.js

Urql version

urql v3.0.0

Validations

  • I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
  • Read the docs.
  • Follow our Code of Conduct
@kitten
Copy link
Member

kitten commented Aug 21, 2022

Turns out this was a simple oversight in the interaction between react-urql and the Client.

I also want to take this opportunity to "advertise" that while we never anywhere call this out explicitly that setting a default policy of cache-and-network has a couple of drawbacks, mainly however, that it will lead to excessive network requests, obviously.
That's why instead, we'd recommend to only switch to it depending on the TTL with the requestPolicyExchange: https://formidable.com/open-source/urql/docs/api/request-policy-exchange/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants