Skip to content

Commit b948375

Browse files
committed
fix(runtime): borrow enclosing signal owner for renderer scopes
Renderer blocks (fragment renderers, value-position host descriptors) carry their enclosing scope's signal instance recipe after stampSignalInstanceKey copies the parent's identity for RENDERER_INVOCATION_SITE. scopeSignalOwner was still creating a separate frozen owner with the same instanceKey, because the renderer looked stamped (signalInstanceParent set) and skipped the existing host-fragment borrow path. The duplicate owner caused: - Declarations and event-owner captures landing in a different cell store than SSR, which keeps one owner per key - Retiring that duplicate on renderer unmount, potentially disposing cells the parent component still owns Fix: pre-mark renderer scopes with false in SCOPE_SIGNAL_OWNERS during stamping, then detect the borrowed identity in scopeSignalOwner by checking that the scope's recipe fields match its enclosing scope's. When they match, delegate to scopeSignalOwner(enclosing) instead of creating a new owner. The false marker prevents retirement on unmount, matching the existing host-control-fragment borrow pattern.
1 parent 5ca824a commit b948375

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,11 @@ function stampSignalInstanceKey(scope: Scope, key: SignalInstanceKey): void {
913913
scope.signalInstanceValue = renderer ? parent.signalInstanceValue : key.key;
914914
scope.signalInstanceHasKey = renderer ? parent.signalInstanceHasKey : key.hasKey;
915915
scope.signalInstanceResolved = renderer ? parent.signalInstanceResolved : undefined;
916+
// A renderer's identity is its parent's: scopeSignalOwner must borrow the
917+
// enclosing scope's owner rather than mint a duplicate with the same
918+
// instanceKey. Pre-mark false so it enters the borrowed-identity path and
919+
// deletion does not retire the parent's cells.
920+
if (renderer) SCOPE_SIGNAL_OWNERS.set(scope, false);
916921
}
917922

918923
function structuralSignalInstanceKey(
@@ -1017,6 +1022,25 @@ function scopeSignalOwner(scope: Scope | null): SignalOwner | undefined {
10171022
parent = parent.parent ?? parent.block.parentBlock;
10181023
}
10191024
}
1025+
// A renderer carries its enclosing scope's signal instance recipe
1026+
// (stampSignalInstanceKey, RENDERER_INVOCATION_SITE) and is pre-marked
1027+
// false. Borrow the enclosing scope's owner so the renderer does not mint
1028+
// a duplicate with the same instanceKey: the server keeps one owner per
1029+
// key, and retiring a duplicate on unmount would dispose the parent's cells.
1030+
if (
1031+
owner === false &&
1032+
(scope.signalInstanceParent !== null || scope.signalInstanceResolved !== undefined)
1033+
) {
1034+
const enclosing: Scope | null = scope.parent ?? scope.block.parentBlock;
1035+
if (
1036+
enclosing !== null &&
1037+
!(enclosing instanceof LiteBlockImpl) &&
1038+
scope.signalInstanceParent === enclosing.signalInstanceParent &&
1039+
scope.signalInstanceSite === enclosing.signalInstanceSite
1040+
) {
1041+
return scopeSignalOwner(enclosing);
1042+
}
1043+
}
10201044
const retired = owner === null;
10211045
if (!owner || owner.documentOwner !== documentOwner) {
10221046
const ids = scope.block.idState;

0 commit comments

Comments
 (0)