Skip to content

Commit 2e1215e

Browse files
committed
fix: set TEARDOWN_BLOCK in resetScopeChildren and collect nested HeadHoist on client
Bug 1: resetScopeChildren installed TEARDOWN_HANDLER when depth was zero but never assigned TEARDOWN_BLOCK, so teardown errors during mid-render deletion cleanups (e.g. Provider dialect flips) routed through reportCaughtError/reportUncaughtError with a null owner, causing root-level onCaughtError/onUncaughtError callbacks to be silently skipped. Add the missing TEARDOWN_BLOCK = block assignment to match the pattern used by unmountBlock and resetHmrBlock. Bug 2: The SSR compiler emitted nested HeadHoist nodes (title/meta/link inside host elements) via ssrHeadEl/ssrStylesheetResource, but the client-side emitElementHtml children walk had no HeadHoist case, silently dropping them. Client-only renders omitted nested metadata and SSR'd nested head tags were never adopted, updated, or removed on unmount. Collect nested HeadHoist nodes during the emitElementHtml walk via a ctx._nestedHeadNodes accumulator (save/restore pattern matching _switchCalls and _portalCalls) and merge them with top-level head nodes before emitHeadClient.
1 parent 512dc65 commit 2e1215e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/octane/src/compiler/compile.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19518,6 +19518,10 @@ function planJsx(
1951819518
// on `ctx` so we don't thread an extra param through every emit signature.
1951919519
const _prevSwitchCalls = ctx._switchCalls;
1952019520
ctx._switchCalls = [];
19521+
// Nested HeadHoist nodes discovered inside host elements during the
19522+
// emitElementHtml walk — same save/restore pattern as portals/switches.
19523+
const _prevNestedHeadNodes = ctx._nestedHeadNodes;
19524+
ctx._nestedHeadNodes = [];
1952119525
// Top-level Fragment ref pairing stack — same save/restore reason as
1952219526
// portals/switches so nested planJsx invocations (e.g. sub-templates
1952319527
// inside components) don't leak FragmentStart bindings into each other.
@@ -20271,7 +20275,10 @@ function planJsx(
2027120275
for (let i = 0; i < allConstructs.length; i++) allConstructs[i].slotIndex = i + slotBase;
2027220276
// Hoisted head elements take the slots AFTER the constructs (and `plan.head` runs
2027320277
// after `plan.after`), so the scope's `slots` array fills 0,1,…,N,N+1,… packed.
20274-
const headEmit = emitHeadClient(headNodes, ctx, allConstructs.length + slotBase);
20278+
// Merge top-level head nodes with any nested ones collected from host elements.
20279+
const allHeadNodes =
20280+
ctx._nestedHeadNodes.length > 0 ? [...headNodes, ...ctx._nestedHeadNodes] : headNodes;
20281+
const headEmit = emitHeadClient(allHeadNodes, ctx, allConstructs.length + slotBase);
2027520282
// Is a construct's host a real in-template element (append / insert INTO it) vs
2027620283
// the block's own parentNode (insert BEFORE __block.endMarker so the slot's range
2027720284
// stays inside the block)? In-template hosts are the navigated `_el…` vars and the
@@ -21078,6 +21085,8 @@ function planJsx(
2107821085
}
2107921086
// Restore the outer plan's switch-call list — pairs with the save above.
2108021087
ctx._switchCalls = _prevSwitchCalls;
21088+
// Restore the outer plan's nested-head-node list — pairs with the save above.
21089+
ctx._nestedHeadNodes = _prevNestedHeadNodes;
2108121090
// Restore the outer plan's fragment-ref pairing stack.
2108221091
if (ctx._fragRefStack && ctx._fragRefStack.length) {
2108321092
throw new Error('Unclosed <Fragment ref={…}> — FragmentStart without matching FragmentEnd');
@@ -23689,6 +23698,8 @@ function emitElementHtml(
2368923698
appendTemplatePart(html, '<!>', 'anchor');
2369023699
childIdx++;
2369123700
}
23701+
} else if (child.type === 'HeadHoist') {
23702+
(ctx._nestedHeadNodes ??= []).push(child);
2369223703
}
2369323704
}
2369423705
}

‎packages/octane/src/runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7016,6 +7016,7 @@ function resetScopeChildren(scope: Scope): void {
70167016
const block = scope.block;
70177017
if (TEARDOWN_DEPTH === 0) {
70187018
TEARDOWN_HANDLER = findTryHandler(block.parentBlock) ?? rendererRegionTryHandler(block);
7019+
TEARDOWN_BLOCK = block;
70197020
}
70207021
TEARDOWN_DEPTH++;
70217022
// The bracket spans the WHOLE reset, not just the teardown call: a queued error is dispatched

0 commit comments

Comments
 (0)