Skip to content

Commit 044cb13

Browse files
add a comment about building console replay before awaiting promise
1 parent 033fa74 commit 044cb13

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

node_package/src/serverRenderReactComponent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ function createFinalResult(
121121
componentName: string,
122122
throwJsErrors: boolean
123123
): null | string | Promise<RenderResult> {
124+
// Node can handle multiple rendering requests simultaneously.
125+
// Console history is stored globally in `console.history`.
126+
// To prevent cross-request data leakage:
127+
// 1. We build the consoleReplayScript here, before any async operations.
128+
// 2. The console history is reset after the sync part of each request.
129+
// This causes console logs happening during async operations to not be captured.
124130
const consoleReplayScript = buildConsoleReplay();
125131

126132
const { result } = renderState;
@@ -163,7 +169,7 @@ function serverRenderReactComponentInternal(options: RenderParams): null | strin
163169

164170
// Finalize the rendering result and prepare it for server response
165171
// 1. Builds the consoleReplayScript for client-side console replay
166-
// 2. Handles both synchronous and asynchronous (Promise) results
172+
// 2. Extract the result from promise (if needed) by awaiting it
167173
// 3. Constructs a JSON object with the following properties:
168174
// - html: string | null (The rendered component HTML)
169175
// - consoleReplayScript: string (Script to replay console outputs on the client)

0 commit comments

Comments
 (0)