Skip to content

Commit 1b8e964

Browse files
justin808claude
andcommitted
Fix console replay test to handle multiple script tags
When multiple React components with replay_console are rendered on the same page, each creates its own <script id="consoleReplayLog"> tag. Nokogiri's .text method concatenates text from all matching elements without separators, causing console log statements to be joined without newlines. Fixed by explicitly mapping over all script tags and joining their text with newlines before parsing. This fix avoids adding runtime complexity or requiring users to call new helper methods. The existing behavior (multiple script tags per component) is preserved. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 345f8f3 commit 1b8e964

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

react_on_rails_pro/spec/dummy/spec/requests/renderer_console_logging_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626

2727
expected_lines = expected.split("\n")
2828

29-
script_node = html_nodes.css("script#consoleReplayLog")
30-
script_lines = script_node.text.split("\n")
29+
# When multiple components with replay_console are rendered, each creates its own script tag
30+
# with id="consoleReplayLog". Nokogiri's .text concatenates them without separators, which
31+
# breaks parsing. Instead, we explicitly join them with newlines.
32+
script_nodes = html_nodes.css("script#consoleReplayLog")
33+
script_text = script_nodes.map(&:text).join("\n")
34+
script_lines = script_text.split("\n")
3135

3236
# Remove leading blank line if present (old format had it, new format doesn't)
3337
script_lines.shift if script_lines.first && script_lines.first.empty?

0 commit comments

Comments
 (0)