-
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
Unexpected Data Fetching with useBackgroundQuery
, StrictMode, fetchPolicy
: network-only
(or no-cache
), and state changes
#11815
Comments
Hi @misacorn 👋🏻 thanks for reporting this and for providing a reproduction! We'll take a look at figure out next steps. |
@jerelmiller Thank you so much! This fix is a lifesaver for our product. |
@wand2016 Awesome! If you need a temporary fix until we get this out, you should be able to downgrade to 3.9.9 which doesn't have this issue. It was introduced in 3.9.10. Not sure if you depend on any of the functionality in 3.10 but wanted to give you this option as well! I'm hoping we can get this patch out quickly though so you don't have to do this 🙂 |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
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. |
Issue Description
When utilizing
useBackgroundQuery
alongside React StrictMode and settingfetchPolicy
tonetwork-only
orno-cache
, coupled with state changes within the same component as theuseBackgroundQuery
call, it leads to the creation of a newqueryRef
instance. Consequently, this triggers undesired refetching behavior.Link to Reproduction
https://codesandbox.io/p/sandbox/cool-shadow-3nm9s9?file=%2Fsrc%2FApp.js%3A58%2C35
Reproduction Steps
increment %d
button.Grandchild
component is re-rendered with a newqueryRef
instance, resulting in undesired fetching.cool-shadow-3nm9s9.-.CodeSandbox.-.Google.Chrome.2024-04-27.23-00-30.mp4
Note
disabling
StrictMode
fixes the issue.cool-shadow-3nm9s9.-.CodeSandbox.-.Google.Chrome.2024-04-27.23-03-39.mp4
Expected Behavior
The
useBackgroundQuery
hook should not create a newqueryRef
instance upon state changes within the same component, as long as it does not alter the options of the hook call.Actual Behavior
The combination of the mentioned factors leads to the creation of a new
queryRef
instance, resulting in unexpected fetching behavior.@apollo/client
version3.10.1
The text was updated successfully, but these errors were encountered: