Skip to content

fix(native-chat): keep diagram source mounted and retire reveal history - #26690

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/native-chat-reveal-followups
Oct 11, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/native-chat-reveal-followups

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​225 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​212
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43

ELI5

Two small problems in native chat, left over from #26238 (replies that flow in):

  1. If you scrolled a wide diagram's source code sideways while a reply was still streaming, the scroll snapped back to the left when the reply finished, a moment before the drawn diagram replaced the source.
  2. An open chat kept a list of every reply it had ever shown, for as long as the chat stayed open, even after those replies left the loaded history. The list only grew.

Both are fixed. Nothing else about how replies or diagrams look should change.

What Changed

What you see

  • Before: you scroll a wide Mermaid source block sideways while the reply streams, and it jumps back to the left edge when the reply finishes. Focus on the block's Copy button and any text selected inside it could also be lost.
  • After: the block stays exactly where you left it until the drawn diagram replaces it (or the error, if the diagram is invalid).
  • Theme switch: an already-drawn diagram stays on screen until it is redrawn in the new theme, as before.

Mechanism

  • Before, a Mermaid fence in a streaming native-chat reply was rendered as a plain code block. When streaming ended, the code block was rebuilt inside a new diagram component, so React threw away the old block and created a new one, with scroll position 0.
  • Now native chat renders the fence through the same diagram component from the first streamed line. A new renderEnabled prop on MermaidBlock keeps Mermaid idle while the reply streams, so the source block underneath is the same element throughout.
  • A drawn result is only reused if it was made from the current source, so a reply that grows again shows its new source, never an outdated diagram.
  • The sidebar, PR-comment markdown and editor preview don't pass these new props, so they behave exactly as before.

Reveal history

  • The reveal tracker remembers which rows it has already shown, so a folded subagent section that is closed and reopened does not replay its reply.
  • It now forgets a row once that message is no longer loaded: no longer in the chat's messages or any subagent section. A closed section's messages are still loaded, so reopening still doesn't replay. The memory is now bounded by the loaded history window.

Why

  • Diagram: keeping one mounted element preserves everything the browser owns (scroll, focus, selection) without saving and restoring scroll positions by hand. The only new piece is one opt-in prop.
  • Reveal history: keying retirement off the messages the chat has already loaded needs no timer, no saved flag and no new store.
  • Alternatives considered:
    • Deriving "already revealed" from message timestamps doesn't work: they can be missing, and over SSH or WSL they come from another machine's clock.
    • A streaming flag misses agents that deliver whole replies.
    • "Not loaded last time" is wrong, because a reply can be loaded before it has a visible row.

Linked Issue

Follow-up to #26238, originally contributed by @AmoabaKelvin. No separate issue.

Visual Proof

Recorded in a hidden, isolated dev build on Windows. A stand-in agent streamed a fixed reply with a wide Mermaid diagram. The source was scrolled sideways with a real horizontal mouse-wheel event while the reply streamed. Base is merged #26238 (3c075883ed3); after is this PR (5c31c8795bd).

Reply just finished, diagram not drawn yet

Before: the source has snapped back to the left After: the source keeps the reader's scroll
before after

What the samples show:

  • Before: about 370 ms after the reply finished, a new source block mounted at scroll position 0 and stayed there for about 125 ms, until the diagram replaced it.
  • After: the same block stayed connected at scroll position 500 in every sample: 415 while streaming and 47 between the end of the reply and the diagram, taken per animation frame and on each DOM change.
  • Then: the diagram replaced the source:

diagram drawn

Theme switch (dark → light → dark)

  • The drawn diagram never fell back to source in any of 155 samples, and it was redrawn for each theme.
  • A blank of about 48 ms during each redraw also happens on base and is not caused by this PR; it is left for a separate follow-up.
Dark Light
dark light

Later replies

  • A second reply still flows in: 69 distinct lengths, with the largest single jump 14 characters.
  • The first reply did not replay.
  • A diagram that was invalid partway through the stream and valid at the end rendered with no error:

second reply

Not checked in the app:

  • selection or focus inside the source block (covered by unit tests)
  • sidebar and PR-comment diagrams (unchanged code path, covered by the existing suites)
  • macOS and Linux
  • real agent CLIs

Testing

  • I manually tested these changes locally (hidden dev build on Windows, see Visual Proof)
  • Automated tests added/updated

Each new test fails when the fix it covers is undone:

  • Diagram source: the same connected element, scrollLeft 90 and the Copy button's focus all survive the end of streaming, until the diagram or its error is ready.
  • Theme switch: a drawn diagram stays while its redraw is pending, and the source never comes back.
  • Mermaid while streaming: Mermaid is never called for a reply that is still streaming.
  • Folded sections: in the real message list, a streaming subagent reply that was shown doesn't replay when its section is closed and reopened.
  • Retirement: rows that left the loaded history are forgotten.

Runs:

  • 559 tests in 66 files pass: native-chat transcript, message list, subagent, reveal, markdown and paced-text suites, plus sidebar CommentMarkdown*/CommentMermaidBlock* and editor MermaidBlock suites.
  • Renderer typecheck and the CI static checks (orca-ci-checks) pass locally.

Review

The PR went through two review rounds and a release-readiness check. The review summary is in a PR comment.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Renderer only: no saved data, protocol or wire format, mobile code (mobile/ imports none of the changed modules) or keyboard shortcuts change.
  • Local and remote: local and SSH sessions render the same way.
  • Performance: the extra work per streamed update is about 0.03 ms with 2,000 loaded messages.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

MermaidBlock now accepts a render-enabled flag and stores render results with their source content. Comment markdown passes the flag through its Mermaid rendering path. Tests cover pending renders, failures, streaming replies, and theme changes. NativeChatMessageList now passes loaded message IDs to reply reveal tracking. The hook updates its known-ID inventory as rows are loaded or removed. Tests cover transcript history, subagent sections, and rows that leave and re-enter loaded history.


Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 5c31c

Changing loaded history windows can replay a reply’s reveal animation. This is a localized visual defect, so the PR remains mergeable with a follow-up fix.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies both primary changes: preserving Mermaid diagram source state and retiring reveal history.
Description check Passed The description is complete and aligned with the template. It explains the user impact, mechanism, rationale, testing, visual proof, compatibility considerations, and checklist status. It references f…

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

…history by message id

- MermaidBlock: a result goes stale only when its source changes, so a theme switch keeps
  the old diagram until the new one renders instead of flashing back to source.
- Reply reveals keep only loaded message ids (conversation rows plus subagent rows), since
  only message rows reveal; drops the separate row inventory and restores nativeChatSlotKey
  to the slots module.
- CommentMarkdownDocumentPre: drop the unreachable renderMermaid half of the fence check.
- Tests: Mermaid stays idle while streaming (waits past the async load), theme change keeps
  the diagram, held renders are settled after each test, a reopened subagent section does
  not replay its streaming reply through the real list, and retirement is tested by outcome.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0a6aa57-71b3-4b2d-9e58-5994cd0274f7
📥 Commits

Reviewing files that changed from the base of the PR and between 2f3f001 and 5c31c87.

📒 Files selected for processing (8)
  • src/renderer/src/components/editor/MermaidBlock.tsx
  • src/renderer/src/components/native-chat/NativeChatMarkdown.mermaid.test.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageList.subagent-sections.test.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageList.tsx
  • src/renderer/src/components/native-chat/NativeChatTranscriptItems.tsx
  • src/renderer/src/components/native-chat/native-chat-reply-reveals.test.tsx
  • src/renderer/src/components/native-chat/native-chat-reply-reveals.ts
  • src/renderer/src/components/sidebar/comment-markdown-code-renderers.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

}
// Only message rows reveal, and only loaded ones can return, so nothing else is kept.
for (const key of state.known) {
if (!loadedMessageIds.has(key)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Retire unloaded IDs before classifying the last row.

When the loaded window changes directly from windowAt(0) to windowAt(300), state.known still contains the old 300 IDs at the earlier lastKey check. The hook marks row-599 as a newly begun reply, although it arrived with loaded history. Remove IDs outside loadedMessageIds before that check. Also assert that the replacement window does not begin a reveal. (raw.githubusercontent.com)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary

The problem. Merged #26238 (native chat replies flow in) left two issues:

  • Diagram source: you scroll a wide Mermaid diagram's source sideways while the reply is still streaming. When the reply finishes, the source block is rebuilt, so the scroll snaps back to the left (and focus or a selection inside it could be lost) before the drawn diagram replaces it.
  • Reveal history: an open chat kept the id of every reply it had ever shown, for as long as the chat stayed open, so that list only grew.

What changes for you.

  • Diagram source: the source block now stays exactly where you left it until the drawn diagram (or its error) replaces it.
  • Reveal history: the chat forgets replies once they leave the loaded history. Reopening a folded subagent section still doesn't replay its reply.
  • Everything else: sidebar and PR-comment diagrams, and how replies flow in, are unchanged.

Fixed during review (commit 5c31c87):

  • Theme-switch flash: the first version made every native-chat diagram flash back to its source when the theme changed, including the automatic switch when the app follows the system theme. Drawn diagrams now stay until they are redrawn.
  • Smaller reveal fix: it now remembers only message ids, which are the only thing the reveal reads. It drops a separate inventory module, a copied type and a scan of every message on each streamed update.
  • Tests: added tests that fail without each fix:
    • Mermaid never runs while a reply streams.
    • A theme change keeps the drawn diagram.
    • A folded subagent reply doesn't replay when its section reopens, checked in the real message list.
    • Rows that left the loaded history are forgotten. This replaces a test that swapped out the global Set.
  • Pending diagram renders are released between tests, and one dead condition was removed.

Deferred, all small:

  • Already in feat(native-chat): make native chat replies flow in and the transcript glide when following #26238 (follow-ups):
    • On each theme switch a drawn diagram goes blank for about 48 ms and the text below jumps about 50 px. This also happens on main. The likely cause is Mermaid removing the element that shares its render id.
    • A subagent reply that started streaming while its section was closed replays from the start when the section reopens.
    • Raw HTML later in a reply, or opening a reply mid-stream, can still rebuild the source block.
  • Accepted here: a finished diagram whose content changes without streaming shows its source until it is redrawn. This is rare.
  • Nits: CommentMermaidBlock ignores renderEnabled when nothing is pending (no caller does that), and NativeChatMessageList.tsx is close to its line limit.

Verified:

  • Two review rounds plus a design challenge, and a release-readiness check: no P0, P1 or P2 issues. Each new test was confirmed to fail with its fix undone.
  • 559 tests in 66 files pass, along with the renderer typecheck and the CI static checks.
  • In a hidden, isolated dev build on Windows with a stand-in agent:
    • Scroll: the source kept scroll position 500 in every sample through the end of the reply. On base, a new block appeared at 0.
    • Theme switch: the diagram never fell back to source.
    • Later replies: a second reply still flowed in, and a diagram that was invalid mid-stream rendered.
  • CI: green on 5c31c87: 14 passed, 16 skipped as not applicable to this change, none failed. The branch merges cleanly with main.

Not verified:

  • macOS and Linux in the app
  • real agent CLIs
  • selection or focus inside the source block in the app (covered by unit tests)
  • sidebar and PR-comment diagrams in the app (unchanged code, covered by the existing tests)

@brennanb2025
brennanb2025 merged commit 28df519 into main Oct 11, 2026
49 of 51 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/native-chat-reveal-followups branch October 11, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant