Skip to content

(graphcache) - Persist results written while the storage is being read - #3926

Open
dargmuesli wants to merge 1 commit into
urql-graphql:mainfrom
dargmuesli:fix/graphcache/persist-while-hydrating
Open

dargmuesli wants to merge 1 commit into
urql-graphql:mainfrom
dargmuesli:fix/graphcache/persist-while-hydrating

Conversation

@dargmuesli

Copy link
Copy Markdown
Contributor

Summary

With offlineExchange, results written to the cache before the storage's readData() has resolved are never persisted. cacheExchange attaches the storage to the store only once hydration has finished, and updatePersist only queues keys while data.storage is set. In a server-rendered app every query answered from ssrExchange data right after the page loads falls into that window, so the data of the page a visit starts on is missing on the next offline start, unless the query happens to run again later.

Set of changes

  • exchanges/graphcache/src/store/data.ts: updatePersist also queues keys while the store is hydrating, and hydrateData removes each key it restores from the storage from that queue again, so stored data isn't written back.
  • exchanges/graphcache/src/store/store.test.ts: a test that writes a record during hydration and checks that writeData receives it, but not the restored one.
  • A patch changeset for @urql/exchange-graphcache.

This isn't a breaking change.

@changeset-bot

changeset-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f060352

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/exchange-graphcache Patch

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

This branch has not been deployed

No deployments
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 this pull request may close these issues.

1 participant