Ensure variables are kept when refetching with a suspense hook that uses skipToken#12993
Conversation
🦋 Changeset detectedLatest commit: 17abb5c The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: f11b00fc2d73ddc70aae49c8 |
commit: |
There was a problem hiding this comment.
This PR should fix the need for this: testing-library/react-render-stream-testing-library#15
There was a problem hiding this comment.
I updated the failing tests as a result of this change over to the render stream helpers for assertion. With the update to useSuspenseQuery which calls setState in render, the raw render count went up with each of these tests which caused the failure. Rather than increasing the count, I switched over to the render stream library to more accurately represent the committed renders.
Fixes #12989
Alternative to #12992.
The core issue with the current implementation is that the
cacheKeycreated when usingskipTokenis different sinceskipTokendoesn't includevariables. This meant switching from options withvariablestoskipTokenwould create a newObservableQueryviaclient.watchQuery. This also meant you'd have 2 activeObservableQueryinstances. In the reproduction from #12989, this was confirmed where you see 2 fetches when the mutation'srefetchQuerieswas run.This PR fixes the issue by keeping the last used
variablesin state so that the cache key remains the same when switching toskipToken. This maintains the existingObservableQueryinstance and puts it in standby mode.