fix: claim late-streamed fragments in chained async memos during hydration#2792
Open
brenelz wants to merge 3 commits into
Open
fix: claim late-streamed fragments in chained async memos during hydration#2792brenelz wants to merge 3 commits into
brenelz wants to merge 3 commits into
Conversation
…ation When a chained async memo (e.g. b = createMemo(() => fetchItems(m())) where m reads a pending async memo a) recomputes after the shell finishes hydrating (sharedConfig.hydrating flips to false) but before the Loading boundary's fragment resume fires, readSerializedOrCompute would re-run the compute function instead of subscribing to the server's serialized deferred Promise. The new client-side Promise resolves after the resume window closes, so the For renders with hydrating=false and creates a fresh node — orphaning the server fragment that $df swaps in: "Hydration completed with 1 unclaimed server-rendered node(s): <div _hk=\"...\">item 1</div>" Fix: track owners whose serialized value has been consumed via a WeakSet. When hydrating is false but the owner's serialized key has not been consumed yet, still read it so the memo subscribes to the server's deferred Promise via handleAsync. The serialized value is only used once; subsequent recomputes use compute(prev) normally.
🦋 Changeset detectedLatest commit: fd8fceb The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
ryansolid
added a commit
that referenced
this pull request
Jun 24, 2026
…stream chunks A chained async memo that recomputes between a streamed <Loading> section's chunks ran its real client body (committing a fresh Promise) because the per-pass `sharedConfig.hydrating` flag is false in that gap. The fresh Promise resolved after the resume window closed, orphaning/duplicating the server-streamed fragment. Treat a computation as still hydrating while the lifecycle is in progress (`!done`) and it has an unconsumed serialized value, so it short-circuits to the server value. Supersedes the WeakSet approach in PR #2792 with a smaller, lifecycle-bound guard. Co-authored-by: Cursor <cursoragent@cursor.com>
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
Fixes an intermittent hydration error that occurs with chained async memos inside a
<Loading>boundary underrenderToStream:Root cause
When a chained async memo (e.g.
b = createMemo(() => fetchItems(m()))wheremreads a pending async memoa) recomputes after the shell finishes hydrating (sharedConfig.hydratingflips tofalse) but before the<Loading>boundary's fragment resume fires,readSerializedOrComputewould re-run the compute function (fetchItems(...)) instead of subscribing to the server's serialized deferred Promise.The new client-side Promise resolves after the boundary's resume window closes, so the
<For>renders withhydrating=falseand creates a fresh node — orphaning the server fragment that\$dfswaps in.Reproduction:
Fix
In
readSerializedOrCompute(packages/solid/src/client/hydration.ts), track owners whose serialized value has been consumed via aWeakSet. Whenhydratingisfalsebut the owner's serialized key has not been consumed yet, still read it so the memo subscribes to the server's deferred Promise viahandleAsync. The serialized value is only used once; subsequent recomputes (e.g. user interactions) usecompute(prev)normally.Test
Adds
packages/solid-web/test/hydration/loading-late-fragment.spec.tsxwhich reproduces the streaming scenario (shell → hydrate → mid chunk resolvesa→ late chunk swaps fragment + resolves3_fr) and asserts:<div>is present (no orphan)unclaimed server-rendered nodewarning firesAll existing tests pass:
solid-webhydration suite: 18 passedsolid-webserver suite: 86 passedsolid-webmain suite: 298 passedsolid-signals: 751 passed