Skip to content

Commit faac53c

Browse files
justin808claude
andcommitted
Revert buildConsoleReplay parameter order to match master
Reverted the parameter order changes from the ill-conceived PR #2097. The correct/original parameter order is: - customConsoleHistory first (most common usage pattern) - numberOfMessagesToSkip second (rarely used) This matches what's currently in master and provides better API ergonomics. Updated: - buildConsoleReplay.ts: Restored original parameter order - serverRenderReactComponent.ts: Updated call sites - buildConsoleReplay.test.js: Updated test calls 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fdfd135 commit faac53c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/react-on-rails/src/buildConsoleReplay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ declare global {
1616
* @internal Exported for tests and for Ruby helper to wrap with nonce
1717
*/
1818
export function consoleReplay(
19-
numberOfMessagesToSkip = 0,
2019
customConsoleHistory: (typeof console)['history'] | undefined = undefined,
20+
numberOfMessagesToSkip: number = 0,
2121
): string {
2222
// console.history is a global polyfill used in server rendering.
2323
const consoleHistory = customConsoleHistory ?? console.history;
@@ -55,11 +55,11 @@ export function consoleReplay(
5555
}
5656

5757
export default function buildConsoleReplay(
58-
numberOfMessagesToSkip = 0,
5958
customConsoleHistory: (typeof console)['history'] | undefined = undefined,
59+
numberOfMessagesToSkip: number = 0,
6060
nonce: string | undefined = undefined,
6161
): string {
62-
const consoleReplayJS = consoleReplay(numberOfMessagesToSkip, customConsoleHistory);
62+
const consoleReplayJS = consoleReplay(customConsoleHistory, numberOfMessagesToSkip);
6363
if (consoleReplayJS.length === 0) {
6464
return '';
6565
}

packages/react-on-rails/src/serverRenderReactComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ async function createPromiseResult(
109109
const consoleHistory = console.history;
110110
try {
111111
const html = await renderState.result;
112-
const consoleReplayScript = buildConsoleReplay(0, consoleHistory);
112+
const consoleReplayScript = buildConsoleReplay(consoleHistory);
113113
return createResultObject(html, consoleReplayScript, renderState);
114114
} catch (e: unknown) {
115115
const errorRenderState = handleRenderingError(e, { componentName, throwJsErrors });
116-
const consoleReplayScript = buildConsoleReplay(0, consoleHistory);
116+
const consoleReplayScript = buildConsoleReplay(consoleHistory);
117117
return createResultObject(errorRenderState.result, consoleReplayScript, errorRenderState);
118118
}
119119
}

packages/react-on-rails/tests/buildConsoleReplay.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ console.warn.apply(console, ["other message","{\\"c\\":3,\\"d\\":4}"]);
7878

7979
it('buildConsoleReplay adds nonce attribute when provided', () => {
8080
console.history = [{ arguments: ['test message'], level: 'log' }];
81-
const actual = buildConsoleReplay(0, undefined, 'abc123');
81+
const actual = buildConsoleReplay(undefined, 0, 'abc123');
8282

8383
expect(actual).toContain('nonce="abc123"');
8484
expect(actual).toContain('<script id="consoleReplayLog" nonce="abc123">');
@@ -87,7 +87,7 @@ console.warn.apply(console, ["other message","{\\"c\\":3,\\"d\\":4}"]);
8787

8888
it('buildConsoleReplay returns empty string when no console messages', () => {
8989
console.history = [];
90-
const actual = buildConsoleReplay(0, undefined, 'abc123');
90+
const actual = buildConsoleReplay(undefined, 0, 'abc123');
9191

9292
expect(actual).toEqual('');
9393
});
@@ -112,7 +112,7 @@ console.warn.apply(console, ["other message","{\\"c\\":3,\\"d\\":4}"]);
112112
console.history = [{ arguments: ['test'], level: 'log' }];
113113
// Attempt attribute injection attack
114114
const maliciousNonce = 'abc123" onload="alert(1)';
115-
const actual = buildConsoleReplay(0, undefined, maliciousNonce);
115+
const actual = buildConsoleReplay(undefined, 0, maliciousNonce);
116116

117117
// Should strip dangerous characters (quotes, parens, spaces)
118118
// = is kept as it's valid in base64, but the quotes are stripped making it harmless

0 commit comments

Comments
 (0)