Skip to content

Commit a1c56e5

Browse files
committed
fix(octane): harden lite-arm proof and nested-arm parentBlock identity
Three bugs in the hookless control-flow arm feature: 1. controlFlowArmIsLite returned false (skip) for ref/event attributes, hiding render-time hook calls in the value expression. Now the value is walked unless it is a direct function expression (callback body). 2. The bare-identifier-call gate only checked CallExpression with a plain Identifier callee. Optional calls and TS-wrapped callees were missed. Now checks OptionalCallExpression and unwraps TSAsExpression etc. 3. A nested @if/@switch inside a lite arm used the LiteBlockImpl stand-in as parentBlock, which lacks disposed and currentRenderMode. Now renderBranchSlot reads those fields from owningBlock(parentBlock).
1 parent 079caed commit a1c56e5

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32908,11 +32908,11 @@ function controlFlowArmIsLite(stmts) {
3290832908
n.name === 'createPortal')
3290932909
)
3291032910
return true;
32911-
if (t === 'CallExpression') {
32912-
const callee = n.callee;
32911+
if (t === 'CallExpression' || t === 'OptionalCallExpression') {
32912+
const callee = unwrapTsExpr(n.callee);
3291332913
if (callee?.type === 'Identifier') return true;
3291432914
if (
32915-
callee?.type === 'MemberExpression' &&
32915+
(callee?.type === 'MemberExpression' || callee?.type === 'OptionalMemberExpression') &&
3291632916
!callee.computed &&
3291732917
callee.property?.type === 'Identifier' &&
3291832918
/^use[A-Z]/.test(callee.property.name)
@@ -32921,7 +32921,15 @@ function controlFlowArmIsLite(stmts) {
3292132921
}
3292232922
if (t === 'Attribute' || t === 'JSXAttribute') {
3292332923
const name = n.name?.name ?? n.name;
32924-
if (typeof name === 'string' && (name === 'ref' || isEventAttrName(name))) return false;
32924+
if (typeof name === 'string' && (name === 'ref' || isEventAttrName(name))) {
32925+
// The callback body runs after render, but the value expression
32926+
// executes at render time: ref={useRef(null)} must be caught.
32927+
const val = n.value;
32928+
const expr = val?.type === 'JSXExpressionContainer' ? val.expression : val;
32929+
if (!expr || expr.type === 'ArrowFunctionExpression' || expr.type === 'FunctionExpression')
32930+
return false;
32931+
return reject(expr);
32932+
}
3292532933
}
3292632934
for (const k in n) {
3292732935
if (AST_WALK_SKIP_KEYS.has(k)) continue;

‎packages/octane/src/runtime.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45305,6 +45305,9 @@ function renderBranchSlot(
4530545305
lite?: boolean,
4530645306
): void {
4530745307
const parentBlock = parentScope.block;
45308+
// A lite arm's stand-in is not a Block: disposal and render-mode state live
45309+
// on the nearest real Block above it (owningBlock traversal).
45310+
const parentOwner = owningBlock(parentBlock);
4530845311
const hydration = hydrating ? activeHydration() : null;
4530945312
if (next !== state.branch) {
4531045313
if (
@@ -45365,15 +45368,15 @@ function renderBranchSlot(
4536545368
}
4536645369
}
4536745370
const swapDriver = TRANSITION_SWAP_DRIVER;
45368-
const transitionMode = parentBlock.currentRenderMode === 'transition';
45371+
const transitionMode = parentOwner.currentRenderMode === 'transition';
4536945372
const committedSuspense =
4537045373
swapDriver !== null &&
4537145374
state.block !== null &&
4537245375
state.block.mounted &&
4537345376
!state.unfinalized &&
4537445377
body !== null &&
4537545378
hydration === null &&
45376-
preservesCommittedSuspense(parentBlock);
45379+
preservesCommittedSuspense(parentOwner);
4537745380
const transitionSwap =
4537845381
ROOT_RENDER_TRANSACTION === null || committedSuspense ? swapDriver : null;
4537945382
const suspenseSwap = !transitionMode && committedSuspense;
@@ -45393,7 +45396,7 @@ function renderBranchSlot(
4539345396
state.block = null;
4539445397
state.unfinalized = false;
4539545398
unmountBlock(pending, false);
45396-
if (parentBlock.disposed) return;
45399+
if (parentOwner.disposed) return;
4539745400
while (node !== null && node !== provisionalAfter) {
4539845401
const nextNode = getNextSibling(node);
4539945402
if ((STAGED_DOM?.view(node) ?? node).parentNode === domParent)
@@ -45405,7 +45408,7 @@ function renderBranchSlot(
4540545408
provisionalAfter = state.lite.block.endMarker;
4540645409
state.unfinalized = false;
4540745410
unmountLiteArm(state, false);
45408-
if (parentBlock.disposed) return;
45411+
if (parentOwner.disposed) return;
4540945412
}
4541045413
// A markerless branch may share its host boundary with a nested sole-root
4541145414
// branch. The nested branch updates Block markers when it replaces that
@@ -45631,7 +45634,7 @@ function renderBranchSlot(
4563145634
STAGED_DOM?.view(oldEnd as ChildNode | null) ?? (oldEnd as ChildNode | null)
4563245635
)?.remove();
4563345636
}
45634-
if (parentBlock.disposed || state.block !== r.wip.block || r.wip.block.disposed) return;
45637+
if (parentOwner.disposed || state.block !== r.wip.block || r.wip.block.disposed) return;
4563545638
return;
4563645639
}
4563745640
}
@@ -45646,11 +45649,11 @@ function renderBranchSlot(
4564645649
const oldBoundaryShared = sharesBlockBoundary(parentBlock, oldBlockStart, oldBlockEnd);
4564745650
if (state.block) {
4564845651
unmountBlock(state.block);
45649-
if (parentBlock.disposed) return;
45652+
if (parentOwner.disposed) return;
4565045653
state.block = null;
4565145654
} else if (state.lite !== null) {
4565245655
unmountLiteArm(state, true);
45653-
if (parentBlock.disposed) return;
45656+
if (parentOwner.disposed) return;
4565445657
}
4565545658
state.branch = next;
4565645659
if (state.start === null && body !== null && oldBoundaryShared) {

0 commit comments

Comments
 (0)