Skip to content

Commit 896042f

Browse files
committed
fix(octane): restore unframed suspend resume mode and rejection marker cleanup
renderUnframed's simplification removed two essential mechanisms: 1. Suspend handling: when a body suspended inside renderUnframed, the unframedClaims WeakMap saved the context so that renderSuspended and the componentSlot/componentSlotLite warm paths could re-enter the correct rendering mode (replayDepth raised for client-built regions, renderInPlace for positional server nodes). Without this, a retry after suspend ran as an ordinary hydrating render at depth 0, which could mis-adopt server siblings or lose the in-place context. 2. Rejection handling: when a seeded rejection escaped the body, the old code removed the fresh comp/end markers so the boundary's catch arm could find and adopt the server's catch content intact. Without this, the markers and the server catch arm both survived, leading to duplicate visible content. This commit restores both mechanisms adapted to the new renderUnframed signature: unframedSuspends stores [root, scope, slotKey, start] per owner block on suspend, renderSuspended walks parent blocks to detect unframed context, and componentSlot/componentSlotLite warm paths check for saved unframed state before re-rendering.
1 parent faa64c6 commit 896042f

1 file changed

Lines changed: 106 additions & 14 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11997,6 +11997,22 @@ export function componentSlotLite<P>(
1199711997
);
1199811998
return;
1199911999
}
12000+
} else if (hydration !== null) {
12001+
const uf = hydration.unframedSuspend(scope.block as Block);
12002+
if (uf !== undefined) {
12003+
hydration.renderUnframed(
12004+
() => componentSlotLite(parentScope, slotKey, host, comp, props, invocationSite),
12005+
undefined,
12006+
scope.block.endMarker!,
12007+
uf[0],
12008+
uf[1],
12009+
uf[2],
12010+
scope.block as Block,
12011+
uf[3],
12012+
);
12013+
hydration.node = getNextSibling(scope.block.endMarker!);
12014+
return;
12015+
}
1200012016
}
1200112017
const prevScope = CURRENT_SCOPE;
1200212018
const warmPlanCheckpoint = ACTIVE_WARM_PLANS.length;
@@ -12088,6 +12104,8 @@ function mountUnframedLite<P>(
1208812104
root ?? null,
1208912105
parentScope,
1209012106
slotKey,
12107+
(parentScope.slots[slotKey] as Scope).block as Block,
12108+
start,
1209112109
);
1209212110
hydration.node = getNextSibling(end);
1209312111
}
@@ -19229,6 +19247,9 @@ class HydrationCapability {
1922919247
private readonly unframedRootRanges = new WeakMap<Node, Node>();
1923019248
/** Adopted ranges whose first render suspended, by block, with its slot (renderClaimed). */
1923119249
private suspendedClaims: WeakMap<Block, readonly [Scope, number]> | null = null;
19250+
/** Unframed renders that suspended, by owner block (renderUnframed). */
19251+
private unframedSuspends: WeakMap<Block, readonly [Node | null, Scope, number, Node]> | null =
19252+
null;
1923219253
/** The server node renderInPlace's body may adopt, until a template does. */
1923319254
private inPlace: Node | null = null;
1923419255
/** Whether inPlace stands after the fresh markers of renderUnframed's call. */
@@ -19528,7 +19549,10 @@ class HydrationCapability {
1952819549
* roots match, and `end` then moves past them, framing them as the server's
1952919550
* range would have. A body that adopts nothing there does not match what
1953019551
* the server rendered. In a client-built region (`root` null), the body
19531-
* adopts nothing but still consumes its positional seeds.
19552+
* adopts nothing but still consumes its positional seeds. A suspension
19553+
* leaves the server nodes in place and saves the context for a retry
19554+
* (unframedSuspend). A seeded rejection removes the fresh markers so the
19555+
* boundary's catch arm finds the server's catch content intact.
1953219556
*/
1953319557
renderUnframed<T>(
1953419558
render: (target: T) => void,
@@ -19537,37 +19561,83 @@ class HydrationCapability {
1953719561
root: Node | null,
1953819562
scope: Scope,
1953919563
slotKey: number,
19564+
owner: Block,
19565+
start: Node,
1954019566
): void {
1954119567
if (root === null) {
1954219568
const previousReplay = this.replayDepth;
1954319569
const previousNative = setNativeAdoptionResolver(null);
1954419570
this.replayDepth = ++this.depth;
1954519571
try {
1954619572
render(target);
19573+
} catch (error) {
19574+
if (isSuspenseException(error))
19575+
(this.unframedSuspends ??= new WeakMap()).set(owner, [root, scope, slotKey, start]);
19576+
else if (this.isRejection(error)) removeRange(start, getNextSibling(end));
19577+
throw error;
1954719578
} finally {
1954819579
this.depth--;
1954919580
this.replayDepth = previousReplay;
1955019581
setNativeAdoptionResolver(previousNative);
1955119582
}
19583+
this.unframedSuspends?.delete(owner);
1955219584
return;
1955319585
}
1955419586
this.node = root;
19555-
if (!this.renderInPlace(render, target, root, true))
19556-
this.slotMismatch(scope, slotKey, 'a component range', root);
19587+
try {
19588+
if (!this.renderInPlace(render, target, root, true))
19589+
this.slotMismatch(scope, slotKey, 'a component range', root);
19590+
} catch (error) {
19591+
if (isSuspenseException(error)) {
19592+
(this.unframedSuspends ??= new WeakMap()).set(owner, [root, scope, slotKey, start]);
19593+
this.node = root;
19594+
} else if (this.isRejection(error)) {
19595+
removeRange(start, getNextSibling(end));
19596+
this.node = root;
19597+
}
19598+
throw error;
19599+
}
19600+
this.unframedSuspends?.delete(owner);
1955719601
domNode(domNode(end).parentNode!).insertBefore(end, this.node);
1955819602
}
1955919603

19604+
/** The suspended unframed render context `block` left for its retry. */
19605+
unframedSuspend(block: Block): readonly [Node | null, Scope, number, Node] | undefined {
19606+
return this.unframedSuspends?.get(block);
19607+
}
19608+
1956019609
/**
19561-
* Resume `source`, the block that a preserved activation suspended in. A
19562-
* source whose first render into its adopted range suspended claims that
19563-
* range again, as the render that suspended did.
19610+
* Resume `source`, the block that a preserved activation suspended in.
19611+
* Inside a component whose unframed render suspended, it renders without
19612+
* adopting, as that render did, and the component completes its claim when
19613+
* its own slot renders it again. A source whose first render into its
19614+
* adopted range suspended claims that range again, as the render that
19615+
* suspended did.
1956419616
*/
1956519617
renderSuspended(source: Block): void {
19566-
const claim = this.suspendedClaims?.get(source);
19567-
if (claim !== undefined) {
19568-
this.suspendedClaims!.delete(source);
19569-
this.renderClaimed(source, claim[0], claim[1]);
19570-
} else renderBlock(source);
19618+
const suspends = this.unframedSuspends;
19619+
let unframed = false;
19620+
if (suspends !== null)
19621+
for (let block: Block | null = source; block !== null && !unframed; block = block.parentBlock)
19622+
unframed = suspends.has(block);
19623+
if (!unframed) {
19624+
const claim = this.suspendedClaims?.get(source);
19625+
if (claim !== undefined) {
19626+
this.suspendedClaims!.delete(source);
19627+
this.renderClaimed(source, claim[0], claim[1]);
19628+
} else renderBlock(source);
19629+
return;
19630+
}
19631+
const previousReplay = this.replayDepth;
19632+
const previousNative = setNativeAdoptionResolver(null);
19633+
this.replayDepth = ++this.depth;
19634+
try {
19635+
renderBlock(source);
19636+
} finally {
19637+
this.depth--;
19638+
this.replayDepth = previousReplay;
19639+
setNativeAdoptionResolver(previousNative);
19640+
}
1957119641
}
1957219642

1957319643
/**
@@ -32834,21 +32904,43 @@ function componentSlotImpl(
3283432904
if (state.inherited) b.exclusiveMarkers = true;
3283532905
state.block = b;
3283632906
if (unframed !== undefined)
32837-
hydration!.renderUnframed(renderBlock, b, b.endMarker!, unframed, parentScope, slotKey);
32907+
hydration!.renderUnframed(
32908+
renderBlock,
32909+
b,
32910+
b.endMarker!,
32911+
unframed,
32912+
parentScope,
32913+
slotKey,
32914+
b,
32915+
b.startMarker!,
32916+
);
3283832917
// The server may have rendered more in the frame, for another component.
3283932918
else if (adoptedFrame) hydration!.renderClaimed(b, parentScope, slotKey);
3284032919
else if (replaced) hydration!.renderUpdate(b);
3284132920
else renderBlock(b);
3284232921
}
3284332922
} else if (state.block) {
32923+
// A claim whose unframed render suspended completes here.
32924+
const uf = hydration === null ? undefined : hydration.unframedSuspend(state.block);
3284432925
// `memo(Component)` — skip the body when new props shallow-equal the
3284532926
// committed props (React.memo's contract; see tryMemoBail). A string comp
3284632927
// is never memo-wrapped, so it falls through to the re-render below.
32847-
if (tryMemoBail(state.block, identity, props)) return;
32928+
if (uf === undefined && tryMemoBail(state.block, identity, props)) return;
3284832929
if (state.block.props !== renderProps)
3284932930
journalRootProperty(state.block, 'props', state.block.props);
3285032931
state.block.props = renderProps;
32851-
renderBlock(state.block);
32932+
if (uf === undefined) renderBlock(state.block);
32933+
else
32934+
hydration!.renderUnframed(
32935+
renderBlock,
32936+
state.block,
32937+
state.block.endMarker!,
32938+
uf[0],
32939+
uf[1],
32940+
uf[2],
32941+
state.block,
32942+
uf[3],
32943+
);
3285232944
}
3285332945
// Hydration: advance the cursor PAST this component's adopted range so the next
3285432946
// sibling adopts from the right node. The body itself doesn't reliably leave the

0 commit comments

Comments
 (0)