Skip to content

Commit

Permalink
make consoleHistory argument of consoleReplay optional
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Sep 30, 2024
1 parent 6d1bfca commit 78c050c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion node_package/src/ReactOnRails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ ctx.ReactOnRails = {
* Used by Rails server rendering to replay console messages.
*/
buildConsoleReplay(): string {
return buildConsoleReplay(console.history);
return buildConsoleReplay();
},

/**
Expand Down
8 changes: 5 additions & 3 deletions node_package/src/buildConsoleReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ declare global {
}
}

export function consoleReplay(consoleHistory: typeof console['history']): string {
export function consoleReplay(customConsoleHistory: typeof console['history'] | undefined = undefined): string {
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.
Expand Down Expand Up @@ -41,6 +43,6 @@ export function consoleReplay(consoleHistory: typeof console['history']): string
return lines.join('\n');
}

export default function buildConsoleReplay(consoleHistory: typeof console['history']): string {
return RenderUtils.wrapInScriptTags('consoleReplayLog', consoleReplay(consoleHistory));
export default function buildConsoleReplay(customConsoleHistory: typeof console['history'] | undefined = undefined): string {
return RenderUtils.wrapInScriptTags('consoleReplayLog', consoleReplay(customConsoleHistory));
}

0 comments on commit 78c050c

Please sign in to comment.