Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Sep 30, 2024
1 parent 78c050c commit c72f369
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions node_package/src/buildConsoleReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export function consoleReplay(customConsoleHistory: typeof console['history'] |
const consoleHistory = customConsoleHistory ?? console.history;

// console.history is a global polyfill used in server rendering.
// Must use Array.isArray instead of instanceof Array the history array is defined outside the vm if node renderer is used.
// In this case, the Array prototype used to define the array is not the same as the one in the global scope inside the vm.
// $FlowFixMe
if (!(Array.isArray(consoleHistory))) {
return '';
Expand Down
5 changes: 5 additions & 0 deletions node_package/src/serverRenderReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,18 @@ as a renderFunction and not a simple React Function Component.`);

try {
const awaitedRenderResult = await renderResult;

// If replayServerAsyncOperationLogs node renderer config is enabled, the console.history will contain all logs happened during sync and async operations.
// If replayServerAsyncOperationLogs node renderer config is disabled, the console.history will be empty, because it will clear the history after the sync execution.
// If the config is disabled, we will return the logs accumulated during the sync execution only.
const consoleHistoryAfterAsyncExecution = console.history;
let consoleReplayScript = '';
if ((consoleHistoryAfterAsyncExecution?.length ?? 0) > (consoleHistoryAfterSyncExecution?.length ?? 0)) {
consoleReplayScript = buildConsoleReplay(consoleHistoryAfterAsyncExecution);
} else {
consoleReplayScript = buildConsoleReplay(consoleHistoryAfterSyncExecution);
}

promiseResult = {
html: awaitedRenderResult,
consoleReplayScript,
Expand Down

0 comments on commit c72f369

Please sign in to comment.