Skip to content

Commit e78631c

Browse files
committed
fix(ssr): set signal declaration invocations during server component renders
The first-declaration-wins guard in RedeclarableBinding.redeclare() keys off currentSignalDeclarationInvocation(), which only the client native-read driver was setting. Server renders stayed at 0, so the guard never fired and the second declaration still installed its definition. This caused a client/server mismatch when a shared cell (duplicate explicit key or an uncompiled hook called twice) was declared, because the client showed the first closure while SSR showed the second. Set unique invocation numbers during server component renders, mirroring what the client driver does in beginRender/endRender. Both renderComponentFramed (nested components) and runFullFramedPass (root component) now bracket their body invocations with setSignalDeclarationInvocation, giving each server render a nonzero invocation so the existing presented guard fires correctly.
1 parent ae34b18 commit e78631c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎packages/octane/src/runtime.server.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { trustHTML, type TrustedHTML } from './trusted-html.js';
22
export { readNativeDomStyle, readNativeDomProps } from './signals/read-protocol.js';
3+
import { setSignalDeclarationInvocation } from './signals/read-protocol.js';
34
/**
45
* octane server runtime (SSR).
56
*
@@ -400,6 +401,7 @@ let NATIVE_SERVER_PASS = -1;
400401
let NATIVE_SERVER_READS: NativeSeedReads | null = null;
401402
let NATIVE_SERVER_FAILURES = 0;
402403
let NATIVE_LOCAL_HOOK_DISPOSES: Array<() => void> | null = null;
404+
let SSR_INVOCATIONS = 0;
403405

404406
/** @internal Enable invocation collection before an opted-in module renders. */
405407
export function enableNativeReadCollection(abi = 1): void {
@@ -5185,6 +5187,7 @@ function renderComponentFramed(
51855187
SIGNAL_CONTROL_SITE = '';
51865188
SIGNAL_LIST_KEYS = rendererListKeys ?? null;
51875189
const nativeToken = NATIVE_READ_COLLECTOR === null ? -1 : beginActiveNativeReadScope(scope);
5190+
const outerInvocation = setSignalDeclarationInvocation(++SSR_INVOCATIONS);
51885191
let nativeCompleted = false;
51895192
try {
51905193
// The compiled body normally returns its HTML string, but a component that
@@ -5258,6 +5261,7 @@ function renderComponentFramed(
52585261
} catch (error) {
52595262
throw normalizeThrownServerThenable(error);
52605263
} finally {
5264+
setSignalDeclarationInvocation(outerInvocation);
52615265
if (nativeToken >= 0) NATIVE_READ_COLLECTOR!.endScope(nativeToken, nativeCompleted);
52625266
CURRENT_SCOPE = previous.scope;
52635267
FRAME = previous.frame;
@@ -8965,6 +8969,7 @@ function runFullFramedPass(
89658969
let signals: NativeSignalManifest | undefined;
89668970
let nativePassCompleted = false;
89678971
const nativeToken = NATIVE_READ_COLLECTOR === null ? -1 : beginActiveNativeReadScope(root);
8972+
const rootOuterInvocation = setSignalDeclarationInvocation(++SSR_INVOCATIONS);
89688973
try {
89698974
// Normalize the root's return the same way ssrComponent normalizes child
89708975
// components: a compiled component returns its HTML string, but a plain
@@ -8985,6 +8990,7 @@ function runFullFramedPass(
89858990
if (!ssrIsSuspense(err)) throw err;
89868991
rootSuspended = true;
89878992
} finally {
8993+
setSignalDeclarationInvocation(rootOuterInvocation);
89888994
vtCandidates = VT_SSR_HAS_CANDIDATES;
89898995
rawHtml = VT_SSR_HAS_RAW_HTML;
89908996
try {

0 commit comments

Comments
 (0)