Skip to content

Commit 5687c6c

Browse files
committed
fix(octane): keep renderer parent pointer at template blocks
A renderer inside a nested `@{ … }` block inherited the block's signalInstanceParent (pointing past the block to the component). scopeSignalOwner then treated the renderer as a template and walked signalInstanceParent, skipping the block entirely. An inner nested block reading the outer block's signal$/derived$/query$ therefore missed the declaring owner and got its own cells. When a renderer's parent has TEMPLATE_INVOCATION_SITE, keep the parent scope itself as signalInstanceParent instead of the parent's parent so the owner walk still visits the block.
1 parent 5208a78 commit 5687c6c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,15 @@ function stampSignalInstanceKey(scope: Scope, key: SignalInstanceKey): void {
965965
}
966966
// A renderer adds no key segment: it carries its parent's identity, and
967967
// stays unstamped below an unstamped parent so keys walk on through it.
968+
// When the parent is a template block (nested `@{ … }`), keep the block
969+
// itself as the parent so scopeSignalOwner still walks through it.
968970
const parent = key.parentScope;
969971
const renderer = key.invocationSite === RENDERER_INVOCATION_SITE;
970-
scope.signalInstanceParent = renderer ? parent.signalInstanceParent : parent;
972+
scope.signalInstanceParent = renderer
973+
? parent.signalInstanceSite === TEMPLATE_INVOCATION_SITE
974+
? parent
975+
: parent.signalInstanceParent
976+
: parent;
971977
scope.signalInstanceSite = renderer ? parent.signalInstanceSite : key.invocationSite;
972978
scope.signalInstanceValue = renderer ? parent.signalInstanceValue : key.key;
973979
scope.signalInstanceHasKey = renderer ? parent.signalInstanceHasKey : key.hasKey;

‎packages/octane/tests/hydration/signal-declaration-owner.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,42 @@ export function App(props) @{
473473
);
474474
});
475475

476+
// A host descriptor inside a nested block creates a renderer. An inner
477+
// nested block rendered through that host must still resolve the outer
478+
// block's signals, not skip past the block to the component.
479+
it.each(MODES)(
480+
"reads the outer block's signal from an inner block through a host ($name)",
481+
async ({ dev, strong }) => {
482+
const view = await mountClient(
483+
`import { query$, signal$ } from 'octane/signals';
484+
export function App(props) @{
485+
const source$ = query$(() => 'source', props.load);
486+
<section>
487+
<output>{source$.snapshot().status as string}</output>
488+
@{
489+
const outer$ = signal$(0);
490+
<div>
491+
@{
492+
const inner = source$.snapshot();
493+
<p><output>{\`\${inner.status === 'ready' ? inner.value : inner.status}:\${outer$.get()}\`}</output></p>
494+
}
495+
</div>
496+
}
497+
</section>
498+
}`,
499+
{ dev, strong },
500+
);
501+
try {
502+
expect(view.requests).toHaveLength(1);
503+
await view.settleAll('ready');
504+
expect(view.texts()).toEqual(['ready', 'ready:0']);
505+
expect(view.requests).toHaveLength(1);
506+
} finally {
507+
view.unmount();
508+
}
509+
},
510+
);
511+
476512
// Returned JSX renders through a fragment renderer, which carries the
477513
// instance of the component it renders for. A nested block inside it still
478514
// reads that component's cells, at the root or below another component.

0 commit comments

Comments
 (0)