@@ -606,9 +606,9 @@ export function syncThenable(value: any) {
606606/**
607607 * A served pass: `write(x)` lands a served answer — the server's answer for a
608608 * node arriving (the async runtime writes it and flushes, synchronously),
609- * or a boundary's fresh render (its trigger; `adopt`: hydrating, so what it
610- * creates adopts its server answer by id, claiming nothing) — and the
611- * flush round that carries it is
609+ * or a boundary's fresh render (its trigger; `adopt`: the boundary's owner,
610+ * hydrating, so what it creates adopts its server answer by id, claiming
611+ * nothing) — and the flush round that carries it is
612612 * hydration's own pass over served answers (`_claimOwner`, that round). A
613613 * node that adopted its own server answer re-runs there because the
614614 * server's answer for something it reads arrived, not because a client
@@ -618,15 +618,22 @@ export function syncThenable(value: any) {
618618 * the flush, where a node it reaches computes. Runs from a settled promise,
619619 * outside any claim window.
620620 */
621- const servedPass = ( write : ( x ?: any ) => void , adopt ?: boolean ) => ( x ?: any ) => {
621+ const servedPass = ( write : ( x ?: any ) => void , adopt ?: Owner | false ) => ( x ?: any ) => {
622622 flush ( ) ;
623623 // Adopting, hydration is on but nothing claims: the render is a client
624- // render, so it opens no snapshot scope either (the `hydrating` setter,
625- // which would release one, is bypassed here). A scope left open would hold
626- // every write made in it — a client-only node's gate (a <Portal>) never
627- // opening.
628- _hydratingValue = _snapshotRootOwner = adopt as any ;
624+ // render, and opens no claim's scope (the `hydrating` setter, which would
625+ // release one, is bypassed here). The boundary's owner is the pass's
626+ // snapshot scope, released with it below: what the render adopts answers
627+ // the inputs the server rendered with, so a client write made before the
628+ // fragment arrived — none of its readers existed then — is served the
629+ // snapshot here, marks its readers stale, and replays at the release: they
630+ // compute against the client's value, as a claimed resume's do (D8,
631+ // #4588). Not a refetch: the input changed (#4273). A scope left open
632+ // would hold every write made in it — a client-only node's gate (a
633+ // <Portal>) never opening.
634+ _hydratingValue = _snapshotRootOwner = ! ! adopt as any ;
629635 _claimOwner = ~ clock ;
636+ if ( adopt ) markSnapshotScope ( adopt ) ;
630637 // An uncaught error (no client boundary for a served error) leaves the
631638 // flush by throwing: the pass still ends, and hydration still completes
632639 // — a boundary's fresh render is its resume, done all the same. (Outside
@@ -637,6 +644,7 @@ const servedPass = (write: (x?: any) => void, adopt?: boolean) => (x?: any) => {
637644 flush ( ) ;
638645 } finally {
639646 _claimOwner = _hydratingValue = _snapshotRootOwner = null as any ;
647+ if ( adopt ) releaseSnapshotScope ( adopt ) ;
640648 checkHydrationComplete ( ) ;
641649 }
642650} ;
@@ -2393,7 +2401,7 @@ function resumeBoundaryHydration(
23932401 // for it, if any (#4287), or an uncaught error — instead of asking
23942402 // again. What the server never sent (a truncated ref is dropped from
23952403 // the registry) computes.
2396- servedPass ( set , shouldHydrate === 0 ) ( ) ;
2404+ servedPass ( set , shouldHydrate === 0 && o ) ( ) ;
23972405 flush ( ) ;
23982406 checkHydrationComplete ( ) ;
23992407}
0 commit comments