Skip to content

Commit 22326e3

Browse files
committed
fix(octane-evals): shadow browser globals in server eval to simulate real Node SSR
The serverModule function evaluates server-compiled code via new Function in the jsdom test context, where window/document/self are defined. This caused typeof window === 'undefined' guards in lazy useState initializers to incorrectly see window as defined, making valid repair patterns (e.g. listener-without-cleanup with added cleanup) fail the server-renders-1024 assertion even though they work correctly in real Node SSR. Shadow window, document, and self as undefined in the new Function parameters so the server evaluation matches real Node.js behavior.
1 parent 8601c41 commit 22326e3

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/octane-evals/datasets/train/user-apps-v1/strong-repair.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ export function serverModule(source: string): Record<string, any> {
5757
if (specifier === 'octane/internal/server') return ServerHelpers;
5858
throw new Error(`Unsupported server-eval import: ${specifier}`);
5959
};
60-
new Function('require', 'module', 'exports', commonJs)(
60+
new Function('require', 'module', 'exports', 'window', 'document', 'self', commonJs)(
6161
requireServerRuntime,
6262
module,
6363
module.exports,
64+
undefined,
65+
undefined,
66+
undefined,
6467
);
6568
return module.exports;
6669
}

0 commit comments

Comments
 (0)