Skip to content

Ensure variables are kept when refetching with a suspense hook that uses skipToken#12993

Merged
jerelmiller merged 33 commits into
mainfrom
jerel/ubq-refetch-skip-token
Oct 31, 2025
Merged

Ensure variables are kept when refetching with a suspense hook that uses skipToken#12993
jerelmiller merged 33 commits into
mainfrom
jerel/ubq-refetch-skip-token

Conversation

@jerelmiller
Copy link
Copy Markdown
Member

@jerelmiller jerelmiller commented Oct 30, 2025

Fixes #12989

Alternative to #12992.

The core issue with the current implementation is that the cacheKey created when using skipToken is different since skipToken doesn't include variables. This meant switching from options with variables to skipToken would create a new ObservableQuery via client.watchQuery. This also meant you'd have 2 active ObservableQuery instances. In the reproduction from #12989, this was confirmed where you see 2 fetches when the mutation's refetchQueries was run.

This PR fixes the issue by keeping the last used variables in state so that the cache key remains the same when switching to skipToken. This maintains the existing ObservableQuery instance and puts it in standby mode.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Oct 30, 2025

🦋 Changeset detected

Latest 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

@apollo-librarian
Copy link
Copy Markdown
Contributor

apollo-librarian Bot commented Oct 30, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: f11b00fc2d73ddc70aae49c8
Build Logs: View logs

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Oct 30, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@12993

commit: 17abb5c

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should fix the need for this: testing-library/react-render-stream-testing-library#15

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been released :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jerelmiller jerelmiller changed the title [WIP] Ensure variables are kept when refetching with a suspense hook that uses skipToken Ensure variables are kept when refetching with a suspense hook that uses skipToken Oct 30, 2025
@jerelmiller jerelmiller marked this pull request as ready for review October 30, 2025 23:21
@jerelmiller jerelmiller requested a review from phryneas October 30, 2025 23:21
@jerelmiller jerelmiller merged commit 8f3bc9b into main Oct 31, 2025
45 checks passed
@jerelmiller jerelmiller deleted the jerel/ubq-refetch-skip-token branch October 31, 2025 17:00
@github-actions github-actions Bot mentioned this pull request Oct 31, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stray revalidation request is sent without variables when revalidating a useBackgroundQuery that is passed a skipToken

2 participants