Skip to content

fix(desktop): render markdown in real time during streaming#3444

Merged
esengine merged 1 commit into
esengine:main-v2from
HUQIANTAO:fix/desktop-streaming-markdown
Jun 7, 2026
Merged

fix(desktop): render markdown in real time during streaming#3444
esengine merged 1 commit into
esengine:main-v2from
HUQIANTAO:fix/desktop-streaming-markdown

Conversation

@HUQIANTAO

Copy link
Copy Markdown
Contributor

Problem

The assistant bubble renders raw plain text while the response is streaming and only switches to rendered markdown (headings, code blocks, lists, tables) once the turn completes. This creates a jarring visual jump — the user reads plain text for seconds, then the entire bubble reflows into formatted markdown.

Root Cause

In Message.tsx, the streaming branch explicitly renders raw text to avoid "markdown reflow jitter":

{item.streaming ? (
  <div className="msg__stream">
    {item.text}           {/* ← raw text, no markdown */}
    <span className="cursor" />
  </div>
) : (
  <Markdown text={item.text} />  {/* ← markdown only on completion */}
)}

The comment says partial markdown "reflows the layout and makes the view jitter." This was true before useDeferredValue was added to <Markdown> (commit f059d71), but now the deferred render handles this gracefully — React prioritises the cursor and layout frame over the expensive parse.

Fix

Render <Markdown> during streaming. The component already uses useDeferredValue internally, so:

  1. New tokens paint immediately (cursor moves, text grows)
  2. The markdown parse runs in idle frames via useDeferredValue
  3. If new tokens arrive mid-parse, React aborts the stale render and starts fresh
  4. No layout jitter — the deferred render is invisible to the user's interaction frame

Changes

File Change
Message.tsx Replace {item.text} with <Markdown text={item.text} /> in the streaming branch; rename .cursor.msg__cursor for BEM consistency
styles.css Update .msg__stream from white-space: pre-wrap to display: flex; flex-direction: column so the cursor sits below the markdown block; add .msg__cursor with margin-top: 4px

Before / After

Before After
During streaming Raw text, no formatting Markdown rendered in real time — headings, code blocks, lists appear as tokens arrive
On completion Sudden reflow to markdown No visual change — already rendered
Performance Fast (plain text) Same — useDeferredValue defers the expensive parse to idle frames

Verification

  • pnpm typecheck ✅ clean
  • pnpm buildbuilt in 5.13s
  • No new dependencies
  • No i18n changes
  • Diff: 2 files, +12 / −10

@github-actions github-actions Bot added desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development labels Jun 7, 2026
@HUQIANTAO HUQIANTAO force-pushed the fix/desktop-streaming-markdown branch from b424ecb to dd69fef Compare June 7, 2026 11:04
The assistant bubble previously rendered raw text while streaming and
only parsed markdown once the turn completed.  This created a jarring
visual jump: plain text for seconds, then a sudden reflow into formatted
markdown with headings, code blocks, and lists.

Now <Markdown> runs on every token.  The component already uses
useDeferredValue internally, so React prioritises the cursor + layout
frame over the expensive parse — new tokens paint immediately and the
formatted catch-up runs in idle frames without blocking interaction.

Changes:
- Message.tsx: replace raw {item.text} with <Markdown> during streaming,
  rename cursor class from .cursor to .msg__cursor for BEM consistency.
- styles.css: update .msg__stream to flex-column layout so the blinking
  cursor sits below the markdown content; keep .cursor for any legacy
  references.
@HUQIANTAO

Copy link
Copy Markdown
Contributor Author

Closing in favor of #3140, which has been rebased on the latest main-v2 (7fba4ab) with the new ProcessCard/TurnActions structure. #3140 is MERGEABLE and CI is green.

This PR was a duplicate of the streaming markdown fix — both change the same lines in Message.tsx. #3140 is the canonical version.

@HUQIANTAO HUQIANTAO closed this Jun 7, 2026
@esengine esengine merged commit 0dd9e8a into esengine:main-v2 Jun 7, 2026
19 checks passed
HUQIANTAO added a commit to HUQIANTAO/DeepSeek-Reasonix that referenced this pull request Jun 7, 2026
The parent task tool card chevron only toggled args/output visibility;
nested sub-agent calls (read_file / grep / ls from an /explore run)
always rendered underneath.  A 50-step /explore flooded the transcript
with its full step list, with no way to fold it back.

Now the open state also controls nested items.  A single chevron click
collapses or expands the whole subagent tree.  Behavior:
- Open by default while the sub-agent is still "running" so the user
  can watch progress.
- Closed by default once it settles, so a finished explore folds to
  a single summary line ("12 steps") on first paint.
- Individual sub-calls can still be expanded/collapsed independently.

This is the ToolCard half of the original esengine#3140.  The streaming-markdown
half has been merged via esengine#3444.
esengine pushed a commit that referenced this pull request Jun 8, 2026
The parent task tool card chevron only toggled args/output visibility;
nested sub-agent calls (read_file / grep / ls from an /explore run)
always rendered underneath.  A 50-step /explore flooded the transcript
with its full step list, with no way to fold it back.

Now the open state also controls nested items.  A single chevron click
collapses or expands the whole subagent tree.  Behavior:
- Open by default while the sub-agent is still "running" so the user
  can watch progress.
- Closed by default once it settles, so a finished explore folds to
  a single summary line ("12 steps") on first paint.
- Individual sub-calls can still be expanded/collapsed independently.

This is the ToolCard half of the original #3140.  The streaming-markdown
half has been merged via #3444.

Co-authored-by: HUQIANTAO <HUQIANTAO@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants