Skip to content

Commit 78c050c

Browse files
make consoleHistory argument of consoleReplay optional
1 parent 6d1bfca commit 78c050c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

node_package/src/ReactOnRails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ ctx.ReactOnRails = {
257257
* Used by Rails server rendering to replay console messages.
258258
*/
259259
buildConsoleReplay(): string {
260-
return buildConsoleReplay(console.history);
260+
return buildConsoleReplay();
261261
},
262262

263263
/**

node_package/src/buildConsoleReplay.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ declare global {
1111
}
1212
}
1313

14-
export function consoleReplay(consoleHistory: typeof console['history']): string {
14+
export function consoleReplay(customConsoleHistory: typeof console['history'] | undefined = undefined): string {
15+
const consoleHistory = customConsoleHistory ?? console.history;
16+
1517
// console.history is a global polyfill used in server rendering.
1618
// Must use Array.isArray instead of instanceof Array the history array is defined outside the vm if node renderer is used.
1719
// 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.
@@ -41,6 +43,6 @@ export function consoleReplay(consoleHistory: typeof console['history']): string
4143
return lines.join('\n');
4244
}
4345

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

0 commit comments

Comments
 (0)