fix: pretty-print raw params and handle escaped newlines#394
fix: pretty-print raw params and handle escaped newlines#394vadimtrunov wants to merge 1 commit intositeboon:mainfrom
Conversation
- Pretty-print JSON in raw params section with proper indentation - Replace escaped \n with actual newlines for readability - Fix Task result title to handle serialized JSON arrays consistently Addresses feedback from PR siteboon#391 review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughThe changes improve JSON content handling in the chat tools UI. One file adds error-tolerant JSON parsing and pretty-printing for raw parameters, while another enhances subagent Task result logic to recognize JSON-serialized arrays delivered as strings and render them consistently. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🤖 Fix all issues with AI agents
Verify each finding against the current code and only fix it if needed.
In `@src/components/chat/tools/components/CollapsibleDisplay.tsx`:
- Around line 70-76: The current inline IIFE in CollapsibleDisplay that returns
JSON.stringify(JSON.parse(rawContent), null, 2).replace(/\\n/g, '\n') mutates
escaped newlines and produces invalid JSON; remove the .replace(/\\n/g, '\n') so
the code returns a valid, pretty-printed JSON string (use
JSON.stringify(JSON.parse(rawContent), null, 2) directly), or if you want
human-readable unescaped newlines only for presentation, perform the replacement
at the rendering layer (after generating the pretty JSON) rather than altering
the JSON string itself; reference: CollapsibleDisplay and the rawContent
handling using JSON.parse/JSON.stringify.
🧹 Nitpick comments (1)
🤖 Fix all nitpicks with AI agents
Verify each finding against the current code and only fix it if needed. In `@src/components/chat/tools/components/CollapsibleDisplay.tsx`: - Around line 70-76: The current inline IIFE in CollapsibleDisplay that returns JSON.stringify(JSON.parse(rawContent), null, 2).replace(/\\n/g, '\n') mutates escaped newlines and produces invalid JSON; remove the .replace(/\\n/g, '\n') so the code returns a valid, pretty-printed JSON string (use JSON.stringify(JSON.parse(rawContent), null, 2) directly), or if you want human-readable unescaped newlines only for presentation, perform the replacement at the rendering layer (after generating the pretty JSON) rather than altering the JSON string itself; reference: CollapsibleDisplay and the rawContent handling using JSON.parse/JSON.stringify.src/components/chat/tools/components/CollapsibleDisplay.tsx (1)
70-76: The\\nreplacement may unintentionally alter JSON structure.After
JSON.stringify, literal\nsequences inside string values are the correct JSON encoding of newlines. Replacing them here means the output is no longer valid JSON — it's a hybrid of JSON structure with unescaped newlines inside string values. If the goal is readability this is fine, but worth noting that\tand other escape sequences (e.g.,\") are left intact, creating an inconsistency.If the intent is purely to make embedded newlines visible, consider doing the replace only on the display string rather than all
\nsequences, or document that this is intentional pretty-printing for human consumption, not valid JSON.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/chat/tools/components/CollapsibleDisplay.tsx` around lines 70 - 76, The current inline IIFE in CollapsibleDisplay that returns JSON.stringify(JSON.parse(rawContent), null, 2).replace(/\\n/g, '\n') mutates escaped newlines and produces invalid JSON; remove the .replace(/\\n/g, '\n') so the code returns a valid, pretty-printed JSON string (use JSON.stringify(JSON.parse(rawContent), null, 2) directly), or if you want human-readable unescaped newlines only for presentation, perform the replacement at the rendering layer (after generating the pretty JSON) rather than altering the JSON string itself; reference: CollapsibleDisplay and the rawContent handling using JSON.parse/JSON.stringify.
|
Hello @vadimtrunov, can you resolve the merge conflicts? |
Summary
\nwith actual newlines for readabilitytitlefunction to handle serialized JSON arrays consistently (applies same parse-if-string logic asgetContentProps)Addresses feedback from #391 review by @blackmammoth (raw params showing literal
\ncharacters) and CodeRabbit suggestion for title consistency.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes