@@ -305,15 +305,14 @@ let _pendingBoundaries = 0;
305305let _hydrationDone = false ;
306306let _snapshotRootOwner : Owner | null = null ;
307307// The boundary owner whose resume window is open (null during a root pass,
308- // which claims everything). Reached as `sharedConfig.isClaiming`.
309- let _claimOwner : Owner | null = null ;
310- // The claim window over no owner: hydration's own pass over served answers,
311- // where nothing claims and a latched node re-serves its server answer
312- // (readSerializedOrCompute) — a hydrated failure's content run (a hydrated
313- // `<Errored>`'s, hydratedCreateErrorBoundary; a rejected fragment's fresh
314- // render over the outcome the server drew for it, resumeBoundaryHydration),
315- // and a served answer's arrival (`servedPass`).
316- const NO_CLAIM = { } as Owner ;
308+ // which claims everything). Reached as `sharedConfig.isClaiming`. Or no
309+ // owner, so nothing claims: `~clock`, a window over the flush round it
310+ // opened in, where a latched node re-serves its server answer
311+ // (readSerializedOrCompute) — hydration's own pass over served answers: a
312+ // hydrated `<Errored>`'s content run (hydratedCreateErrorBoundary) and the
313+ // round a served answer lands in (`servedPass`). Never 0: `~` maps every
314+ // round to a truthy number.
315+ let _claimOwner : Owner | number | null = null ;
317316function isClaiming ( ) : boolean {
318317 if ( ! _claimOwner ) return true ;
319318 let owner : Owner | null = getOwner ( ) ;
@@ -586,29 +585,27 @@ export function syncThenable(value: any) {
586585 } ;
587586}
588587
589- // The flush round a served pass's served answer lands in.
590- let _servedAt : number | undefined ;
591588/**
592589 * A served pass: `write(x)` lands a served answer — the server's answer for a
593590 * node arriving (the async runtime writes it and flushes, synchronously),
594591 * or a rejected fragment's fresh render over the outcome the server drew
595592 * (the boundary's trigger) — and the flush round that carries it is
596- * hydration's own pass (NO_CLAIM). A node that adopted its own server answer
597- * re-runs there because the server's answer for something it reads arrived,
598- * not because a client write diverged it, and re-serves that answer
599- * (readSerializedOrCompute). No client write is swallowed: the ones already
600- * made flush first, outside the pass, and one made during it (an effect's)
601- * runs in a later round of the flush, past `_servedAt`, where a node it
602- * reaches computes. Runs from a settled promise, outside any claim window.
593+ * hydration's own pass over served answers (`_claimOwner`, that round). A
594+ * node that adopted its own server answer re-runs there because the
595+ * server's answer for something it reads arrived, not because a client
596+ * write diverged it, and re-serves that answer (readSerializedOrCompute).
597+ * No client write is swallowed: the ones already made flush first, outside
598+ * the pass, and one made during it (an effect's) runs in a later round of
599+ * the flush, where a node it reaches computes. Runs from a settled promise,
600+ * outside any claim window.
603601 */
604- function servedPass ( write : ( x ?: any ) => void , x ?: any ) {
602+ const servedPass = ( write : ( x ?: any ) => void ) => ( x ?: any ) => {
605603 flush ( ) ;
606- _claimOwner = NO_CLAIM ;
607- _servedAt = clock ;
604+ _claimOwner = ~ clock ;
608605 write ( x ) ;
609606 flush ( ) ;
610- _claimOwner = _servedAt = undefined as any ;
611- }
607+ _claimOwner = null ;
608+ } ;
612609
613610/**
614611 * Unwrap a serialized hydration map entry. Only call when the map HAS an
@@ -643,10 +640,8 @@ export function readHydratedValue(initP: any, refresh: () => void, options?: any
643640 }
644641 // Still in flight (or a loading window's): the runtime lands it, in a
645642 // served pass for the node it lands.
646- if ( typeof initP . then === "function" ) {
647- const arrive = ( f : any ) => ( x : any ) => servedPass ( f , x ) ;
648- return { then : ( a : any , b : any ) => initP . then ( arrive ( a ) , arrive ( b ) ) } ;
649- }
643+ if ( typeof initP . then === "function" )
644+ return { then : ( a : any , b : any ) => initP . then ( servedPass ( a ) , servedPass ( b ) ) } ;
650645 }
651646 return initP ;
652647}
@@ -719,14 +714,15 @@ export function readSerializedOrCompute(compute: (prev: any) => any, prev: any,
719714 // holds: its section's hydration is over, so the rerun answers a client
720715 // write and computes, rather than re-adopting the server value until the
721716 // page's last boundary resumes. Never in hydration's own pass over
722- // served answers (NO_CLAIM): a source's server answer arriving, or a
723- // hydrated failure's content reading the node — a later tracked read
724- // retries an errored async node (PJ-R35) with nothing changed. No client
725- // write diverged it there: it re-serves its own answer, an error
726- // included, and arms nothing — no ask, no loading flash (#4287, #4306).
727- // A later round of an arrival's flush is past that pass (`servedPass`):
728- // an effect's write re-ran the node there.
729- if ( options ?. ssrSource !== "hybrid" && ( _claimOwner !== NO_CLAIM || clock > _servedAt ! ) ) {
717+ // served answers (`_claimOwner` is `~clock`): a source's server answer
718+ // arriving, or a hydrated failure's content reading the node — a later
719+ // tracked read retries an errored async node (PJ-R35) with nothing
720+ // changed. No client write diverged it there: it re-serves its own
721+ // answer, an error included, and arms nothing — no ask, no loading flash
722+ // (#4287, #4306). A served pass covers the round its answer lands in
723+ // (`servedPass`): a later round of that flush is an effect's write
724+ // re-running the node, which computes.
725+ if ( options ?. ssrSource !== "hybrid" && _claimOwner !== ~ clock ) {
730726 let p : Owner | null = o ;
731727 while ( p && ! ( p as any ) . _hp ) p = p . _parent ;
732728 if ( ! p && ! ( sharedConfig . hydrating && isClaiming ( ) ) ) return compute ( prev ) ;
@@ -1334,13 +1330,15 @@ function hydratedCreateErrorBoundary<T, U>(
13341330 // The content's owner, until a fallback is built.
13351331 let o : any ;
13361332 const read = coreErrorBoundary (
1337- // While hydrating, a claim window over no owner: nothing under it
1338- // claims. (`hydrateWindow` with no id or scope, hydration already on
1333+ // While hydrating, a claim window over no owner (`~clock`) : nothing
1334+ // under it claims. (`hydrateWindow` with no id or scope, hydration already on
13391335 // and the snapshot root marked above, only swaps the claim owner.)
13401336 // A later run claims nothing either way: claims are read only while
13411337 // hydrating.
13421338 ( ) =>
1343- _hydratingValue ? hydrateWindow ( "" , fn , undefined , ( ( o = getOwner ( ) ) , NO_CLAIM ) ) : fn ( ) ,
1339+ _hydratingValue
1340+ ? hydrateWindow ( "" , fn , undefined , ( ( o = getOwner ( ) ) , ~ clock as any ) )
1341+ : fn ( ) ,
13441342 ( e , reset ) => ( ( o = 0 ) , fallback ( e , reset ) )
13451343 ) ;
13461344 // No fallback yet: the content ran clean. Hold the server's fallback
@@ -2300,31 +2298,29 @@ function resumeBoundaryHydration(
23002298 checkHydrationComplete ( ) ;
23012299 return ;
23022300 }
2303- if ( shouldHydrate ) {
2304- // A late resume claims against the root this boundary registered under
2305- // (the captured `scope`), its subtree the snapshot and live scope for
2306- // the window; the trigger re-runs the boundary's compute inside it.
2307- hydrateWindow (
2308- id ,
2309- ( ) => {
2310- set ( ) ;
2311- flush ( ) ;
2312- } ,
2313- scope ,
2314- o
2315- ) ;
2316- } else {
2317- // The client renders the boundary fresh (recover): no claim. Over the
2318- // outcome the server drew for the failure (an `<Errored>` fallback the
2319- // swap brought, listed in the reveal record, #4287) it is that
2320- // failure's content run, as a hydrated `<Errored>`'s is: a served pass.
2321- _hydratingValue = false ;
2322- ( globalThis as any ) . _$HY ?. v ?. [ id ] ?. length ? servedPass ( set ) : ( set ( ) , flush ( ) ) ;
2323- }
23242301 // Hydration mode is off once a boundary has resumed — whatever the flag
23252302 // read before (a resume never runs inside a root's synchronous pass; the
2326- // client-gated nodes the resume created compute in the flush below).
2303+ // client-gated nodes the resume created compute in the flush below). A
2304+ // claiming resume turns it on for its window alone.
23272305 _hydratingValue = false ;
2306+ shouldHydrate
2307+ ? // A late resume claims against the root this boundary registered under
2308+ // (the captured `scope`), its subtree the snapshot and live scope for
2309+ // the window; the trigger re-runs the boundary's compute inside it.
2310+ hydrateWindow (
2311+ id ,
2312+ ( ) => {
2313+ set ( ) ;
2314+ flush ( ) ;
2315+ } ,
2316+ scope ,
2317+ o
2318+ )
2319+ : // The client renders the boundary fresh (recover): no claim. Over the
2320+ // outcome the server drew for the failure (an `<Errored>` fallback the
2321+ // swap brought, listed in the reveal record, #4287) it is that
2322+ // failure's content run, as a hydrated `<Errored>`'s is: a served pass.
2323+ ( ( globalThis as any ) . _$HY ?. v ?. [ id ] ?. [ 0 ] ? servedPass ( set ) : set ) ( ) ;
23282324 flush ( ) ;
23292325 checkHydrationComplete ( ) ;
23302326}
@@ -2906,12 +2902,13 @@ function hydratedCreateLoadingBoundary<T, U>(
29062902 // A parked fragment has settled but not swapped: it waits like a pending one.
29072903 const s = fr && typeof fr === "object" ? ( fr . s === 1 && fragmentParked ( id ) ? 0 : fr . s ) : 0 ;
29082904
2909- // Inside a hydrated `<Errored>`'s content run, which claims no DOM (the
2905+ // Inside a hydrated `<Errored>`'s content run (`~clock`, a window
2906+ // over no owner), which claims no DOM (the
29102907 // markup is the server's fallback for the failure, #4287), the
29112908 // fragment is never claimed: the content runs now with its data
29122909 // adopted, so the Errored holds the client's own error and tracks its
29132910 // inputs (#4273).
2914- const unclaimed = _claimOwner === NO_CLAIM ;
2911+ const unclaimed = _claimOwner === ~ clock ;
29152912 // Nothing else consumes a rejected `_fr` promise then — swallow it so
29162913 // a rejected fragment (error finalize or a client-hole handoff) doesn't
29172914 // surface as an unhandled rejection.
0 commit comments