Repository navigation
fix: hydrate cacheData for hooks without a fetcher - #4293
Merged
Merged
Conversation
huozhi
approved these changes
Aug 6, 2026
huozhi
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the PR, I tweaked the implementation a bit so you don't need the extra effect hook
huozhi
force-pushed
the
fix/cachedata-null-fetcher
branch
from
August 6, 2026 16:30
b37e080 to
2d9cf0f
Compare
yongsk0066
added a commit
to yongsk0066/yongsk0066.github.io
that referenced
this pull request
Aug 13, 2026
* feat(about): add SWR v2.5.1 contribution to OSS list vercel/swr#4293 — hydrate cacheData for hooks without a fetcher, merged and shipped in SWR v2.5.1. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PTw2dbxNkF6ribAZDV4d5d * fix(about): correct SWR PR #4293 LOC stat to +425/-14 Verified against the squash-merge commit ad7b276 in vercel/swr (5 files changed, 425 insertions, 14 deletions). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PTw2dbxNkF6ribAZDV4d5d --------- Co-authored-by: Claude <[email protected]>
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hydrate request-scoped
cacheDatainto SWR's cache foruseSWR(key, null)without treating hydration as revalidation.cacheDatavalues.cacheDataobject.Problem
Default-mode
cacheDatawas consumed insiderevalidate. A hook without a fetcher never enters that path, souseSWR(key, null)remained undefined and the server-loaded value was never written into SWR's cache.Tracking consumption only by serialized key also cannot distinguish a fresh request-scoped
cacheDataobject from an already-consumed one. Promised values additionally need protection from key changes and newer local mutations.Solution
After React commits, a fetcherless hook resolves its matching
cacheDatavalue and writes the resulting data or error into the external cache. The commit proceeds only while:A per-hook
WeakMap<CacheData, Set<string>>tracks consumption by request object and serialized key. This lets a fresh request provide new data for the same key while old request objects remain eligible for garbage collection.Hydration does not call
revalidate, soisLoadingandisValidatingremain false, revalidation callbacks do not fire, and no client fetcher runs.Validation
pnpm run-all-checkspassed.pnpm format:checkpassed.pnpm buildpassed.The browser regression verifies real RSC hydration with
useSWR(key, null): the server value reaches both the hook and SWR cache, loading and validating stay false, success callbacks remain at zero, and no client request occurs.