Skip to content

Commit 226e461

Browse files
justin808claude
andcommitted
Fix double-wrapping of console replay script in streaming renderer
The streaming renderer was calling `buildConsoleReplay()` which wraps the console replay JavaScript in a `<script>` tag. However, the Ruby helper then called `wrap_console_script_with_nonce()` again, creating nested script tags: ```html <script id="consoleReplayLog"> <script id="consoleReplayLog"> console.log... </script> </script> ``` This caused the test to fail because Nokogiri's `.text` on the outer script returned the inner `<script id="consoleReplayLog">` as text. **Solution:** Changed streamingUtils.ts to use `consoleReplay()` instead of `buildConsoleReplay()`. The `consoleReplay()` function returns just the JavaScript code without wrapping, allowing the Ruby helper to add the single script tag with proper CSP nonce support. **Fixes:** - Failing test: Console logging from server when replay_console=true - Test file: react_on_rails_pro/spec/dummy/spec/requests/renderer_console_logging_spec.rb:52 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6e61fc5 commit 226e461

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/react-on-rails-pro/src/streamingUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { PassThrough, Readable } from 'stream';
1717

1818
import createReactOutput from 'react-on-rails/createReactOutput';
1919
import { isPromise, isServerRenderHash } from 'react-on-rails/isServerRenderResult';
20-
import buildConsoleReplay from 'react-on-rails/buildConsoleReplay';
20+
import { consoleReplay } from 'react-on-rails/buildConsoleReplay';
2121
import { createResultObject, convertToError, validateComponent } from 'react-on-rails/serverRenderUtils';
2222
import {
2323
RenderParams,
@@ -112,7 +112,7 @@ export const transformRenderStreamChunksToResultObject = (renderState: StreamRen
112112
const transformStream = new PassThrough({
113113
transform(chunk: Buffer, _, callback) {
114114
const htmlChunk = chunk.toString();
115-
const consoleReplayScript = buildConsoleReplay(previouslyReplayedConsoleMessages, consoleHistory);
115+
const consoleReplayScript = consoleReplay(previouslyReplayedConsoleMessages, consoleHistory);
116116
previouslyReplayedConsoleMessages = consoleHistory?.length || 0;
117117
const jsonChunk = JSON.stringify(createResultObject(htmlChunk, consoleReplayScript, renderState));
118118
this.push(`${jsonChunk}\n`);

0 commit comments

Comments
 (0)