Skip to content

Commit 0f8a81f

Browse files
justin808claude
andcommitted
Fix double-wrapping of console replay script in node-renderer
**Root Cause:** The streaming renderer in streamingUtils.ts calls `buildConsoleReplay()` which wraps the console JavaScript in `<script id="consoleReplayLog">` tags. Then the Ruby helper (`react_on_rails_pro_helper.rb:351` and `helper.rb:398`) calls `wrap_console_script_with_nonce()` again, creating nested script tags. When Nokogiri parses the resulting HTML and calls `.text` on the outer script element, it returns the inner `<script id="consoleReplayLog">` tag as TEXT content, causing the test to fail. **Solution:** Changed streamingUtils.ts line 115 and line 20 to use `consoleReplay()` instead of `buildConsoleReplay()`. The `consoleReplay()` function returns ONLY the JavaScript code without wrapping, allowing the Ruby helper to add the single `<script>` tag with proper CSP nonce support. **Why previous attempt failed:** CI uses caching and the prepare script only rebuilds if lib/ doesn't exist. The previous fix didn't trigger a rebuild, so CI used cached (broken) code. **Verified:** - Code analysis confirms double-wrapping issue - TypeScript compiles successfully - Build completes without errors - Change is minimal and targeted **Test:** renderer_console_logging_spec.rb:13 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6c461a1 commit 0f8a81f

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)