Skip to content

Commit d55a50d

Browse files
justin808claude
andcommitted
Fix double-wrapped script tags in console replay
The issue was that serverRenderReactComponent was calling buildConsoleReplay() which wraps the console code in script tags, but Ruby was ALSO wrapping it with wrap_console_script_with_nonce(), resulting in nested script tags like: <script id="consoleReplayLog"><script>...</script></script> Changed serverRenderReactComponent to call consoleReplay() instead, which returns just the JavaScript code without script tags. Ruby then wraps it once with the proper nonce attribute. This fixes the failing tests: - ReactOnRailsProHelper html_streaming_react_component creates a fiber - Console logging from server has server log messages in the script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3a3c4b4 commit d55a50d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isValidElement, type ReactElement } from 'react';
33
// ComponentRegistry is accessed via globalThis.ReactOnRails.getComponent for cross-bundle compatibility
44
import createReactOutput from './createReactOutput.ts';
55
import { isPromise, isServerRenderHash } from './isServerRenderResult.ts';
6-
import buildConsoleReplay from './buildConsoleReplay.ts';
6+
import { consoleReplay } from './buildConsoleReplay.ts';
77
import handleError from './handleError.ts';
88
import { renderToString } from './ReactDOMServer.cts';
99
import { createResultObject, convertToError, validateComponent } from './serverRenderUtils.ts';
@@ -109,11 +109,11 @@ async function createPromiseResult(
109109
const consoleHistory = console.history;
110110
try {
111111
const html = await renderState.result;
112-
const consoleReplayScript = buildConsoleReplay(consoleHistory);
112+
const consoleReplayScript = consoleReplay(consoleHistory);
113113
return createResultObject(html, consoleReplayScript, renderState);
114114
} catch (e: unknown) {
115115
const errorRenderState = handleRenderingError(e, { componentName, throwJsErrors });
116-
const consoleReplayScript = buildConsoleReplay(consoleHistory);
116+
const consoleReplayScript = consoleReplay(consoleHistory);
117117
return createResultObject(errorRenderState.result, consoleReplayScript, errorRenderState);
118118
}
119119
}
@@ -128,7 +128,7 @@ function createFinalResult(
128128
return createPromiseResult({ ...renderState, result }, componentName, throwJsErrors);
129129
}
130130

131-
const consoleReplayScript = buildConsoleReplay();
131+
const consoleReplayScript = consoleReplay();
132132
return JSON.stringify(createResultObject(result, consoleReplayScript, renderState));
133133
}
134134

0 commit comments

Comments
 (0)