Repository navigation
Fix Mermaid diagrams that stay on error after replies finish - #26480
Conversation
|
A valid diagram could remain on “Diagram error” after a chat reply finished because the earlier error display removed the DOM container that later successful renders needed. This change stores the sanitized SVG or error in React state and keeps chat source in its existing code block until the reply stops streaming, so the finished diagram can appear and a later valid source can recover from an error. Self-review covered stale render cancellation, use of sanitized output, serialization of diagram renders, and unchanged default rendering outside native chat. No independent review was run. Fixed: the shared component's stuck error, mid-stream chat parsing, and premature queue reset; deferred: live provider timing and in-app checks of editor/comment surfaces. Verified: 40 targeted tests, both requested regressions failing on the base implementation, renderer typecheck through the machine queue, and all 22 repository static checks before each push. Hidden macOS Electron with a fresh private profile, hooks off, absolute agent stand-ins, and synthetic transcript/status fixtures displayed partial source without an error, a complete real SVG, finished invalid source with the existing error, and invalid-to-valid recovery. Screenshots are embedded above. Not verified: a live provider stream, Linux/Windows, SSH, editor/comment UI, or a base-branch error screenshot. Final head |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughMermaidBlock now stores sanitized SVG or an error in state and preserves queued renders when earlier tasks complete. CommentMarkdown adds a setting to enable or disable Mermaid rendering. NativeChatMarkdown disables rendering while a message is streaming. Tests cover editor rendering, sanitization, queueing, and streaming chat behavior. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Mermaid diagrams stay as source while a reply streams and render once it finishes. A diagram that failed to parse can now recover into a valid render. No merge-blocking issues were found. Unit shard 9 did not complete in CI, so it should be re-run. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
ELI5
A valid diagram in a chat reply could stay on “Diagram error” after the reply finished. An incomplete diagram failed while the reply was arriving, and the error display removed the container that later successful renders needed.
What Changed
Chat now shows a Mermaid fence in the existing code block while the reply is streaming, then renders the diagram when that reply finishes. A real syntax error in a finished reply still shows the existing error and source.
The shared diagram component stores the sanitized SVG or error in React state, so a successful render can replace an error in chat, markdown previews, and expanded comments. Cancelled renders cannot replace newer results, and the serialized render queue resets only after its last waiting render completes.
Why
Intended choice: follow the common pattern of keeping source visible until a reply settles. This avoids parsing half-arrived diagrams and avoids transient error banners; progressively rendering diagrams would require additional recovery and display policy without improving the requested outcome. Keeping the result in React state fixes the shared component’s missing-container failure instead of adding another guard around it.
Linked Issue
Reported while testing native chat on October 7; no separate issue. Kept separate from #26380.
Visual Proof
Hidden macOS Electron check through Playwright CDP, using a private profile, synthetic chat transcript, hooks off, and absolute agent stand-ins. The app used the real Mermaid renderer and DOMPurify; no real provider stream was used. No QA host was allocated within 20 minutes, so this ran hidden on the laptop.
While the reply is streaming, the partial fence uses the existing code block:
Once the reply finishes, the full flowchart renders:
A finished reply with invalid source still shows the existing error and source:
Testing
orca-ci-checkspass. Package scripts were expanded into their exact direct commands to avoid running pnpm through the shared node_modules symlink.Unit tests control the asynchronous Mermaid renderer and sanitizer to test component state, cancellation, queuing, and use of sanitized output; the hidden Electron check exercised the real renderer and sanitizer. Windows, Linux, and SSH have not been exercised locally. The change is renderer-only, uses no host-specific operations, changes no remote protocol or saved data, and applies equally to folder workspaces and git worktrees.
Completed CI run 37742588327 on final head
3135d2424aa9c922bd8cfbafd13091a0393b7798: all 35 checks finished (16 passed, 17 skipped, 2 failed). The failed unit shard 9 is classified infrastructure: GitHub reports “The hosted runner lost communication with the server”; the job ended during its test step without a test result or log blob. The failed verification gate follows that failed unit job. Nine unit shards, static analysis/typecheck, both package jobs, relay integration, and the advisory evidence job passed. Skipped checks are not test passes; shard 9 remains a CI coverage gap. No code assertion failure was reported. Marking the PR ready queued a new automatic run, whose result is not yet verified.Review
Self-reviewed the result state, cancellation, sanitization, queue serialization, and default behavior outside native chat. No independent review was run.
Agent skill upstream boundary
Notes
DOMPurify’s SVG pass remains in place. No dependency, localization, persistence, or remote wire changes.
Checklist