Closed wand2016 closed 6 months ago
Hi @misacorn šš» thanks for reporting this and for providing a reproduction! We'll take a look at figure out next steps.
Hey @wand2016 š
I've got a fix for this with https://github.com/apollographql/apollo-client/pull/11821 and can confirm it fixes the issue given your reproduction. If you want to try this out for yourself, you can install the snapshot release with:
npm i @apollo/client@0.0.0-pr-11821-20240501000021
We'll try and get this out in the next version!
@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. For general questions, we recommend using StackOverflow or our discord server.
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.https://github.com/apollographql/apollo-client/assets/22491120/ac76df0d-f504-4fea-8219-49f7b2dafd88
https://github.com/apollographql/apollo-client/assets/22491120/9646791b-8082-422e-bc23-a6cd4b5ce01d
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