Skip to content

fix(message): render markdown while streaming assistant output#3337

Open
SuMuxi66 wants to merge 2 commits into
esengine:main-v2from
SuMuxi66:fix/streaming-markdown-render
Open

fix(message): render markdown while streaming assistant output#3337
SuMuxi66 wants to merge 2 commits into
esengine:main-v2from
SuMuxi66:fix/streaming-markdown-render

Conversation

@SuMuxi66

@SuMuxi66 SuMuxi66 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR is now a focused follow-up on top of the merged streaming Markdown work in #3444.

It keeps the streaming cursor rendered inside the Markdown flow instead of outside the rendered block, so the cursor placement remains visually consistent while Markdown content is streaming.

Scope

After rebasing onto the latest main-v2, this PR contains only:

  • Markdown.tsx
  • Message.tsx

The original broader streaming Markdown changes are no longer included because #3444 has already landed.

Validation

  • Rebased onto latest origin/main-v2
  • npx tsc --noEmit passes with 0 errors
  • Final diff contains 1 commit:
    • fix(message): keep streaming cursor inside markdown

Notes

This PR also preserves inline Markdown elements such as <strong> and <em> via the cloneElement path.

@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 6, 2026
@SuMuxi66 SuMuxi66 closed this Jun 6, 2026
@SuMuxi66 SuMuxi66 reopened this Jun 6, 2026

@SivanCola SivanCola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this is the right direction and the scope is much cleaner than the broader streaming-markdown work in #3140. I think this PR should be the main path for the focused assistant streaming markdown fix.

Before merging, please fix the streaming cursor placement. Markdown renders a block-level .md wrapper, so rendering <span className="cursor" /> as a sibling after <Markdown /> places the cursor after the markdown block rather than at the end of the rendered text. For normal paragraphs this will show the cursor on the next line, not after the last token.

Please make the cursor render as part of the final rendered markdown content, then verify paragraphs, lists, tables, and code blocks while streaming.

Once this is addressed and verification stays green, I will consider merging it into main-v2.

@SuMuxi66 SuMuxi66 force-pushed the fix/streaming-markdown-render branch from 2118ea7 to 0c8a0a4 Compare June 7, 2026 12:30
@github-actions github-actions Bot added the desktop Wails desktop app (desktop/**) label Jun 7, 2026
@SuMuxi66

SuMuxi66 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated.

Changes addressed:

  • Kept the streaming cursor inside the rendered Markdown content instead of rendering it as a sibling after <Markdown />.
  • Replaced the raw streaming branch with real-time Markdown rendering.
  • Added a showCursor path in Markdown.tsx using a sentinel that is rendered as the cursor inside Markdown content.
  • Covered paragraphs, lists, tables, and code blocks so the sentinel is not shown as raw text.

Verified:

  • git diff --check origin/main-v2..HEAD passes.
  • TypeScript check passes.
  • Manually tested streaming paragraphs, lists, tables, and code blocks.
  • Cursor disappears after the turn completes.

@SuMuxi66 SuMuxi66 requested a review from SivanCola June 7, 2026 15:17
@SuMuxi66

SuMuxi66 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

更新一下当前 PR 状态:

因为 #3444 已经合并到 main-v2,所以这个 PR 已经重新 rebase 到最新 origin/main-v2,并且收窄为一个很小的 follow-up。

当前这个 PR 不再重复实现 streaming Markdown 主逻辑,只保留一个剩余问题修复:

  • streaming 过程中,让光标继续保持在 Markdown 渲染流内部
  • 避免光标跑到渲染块外面,导致视觉位置不一致
  • 保留 <strong> / <em> 等 inline element 的正常渲染,已通过 cloneElement 路径处理

当前最终范围:

  • 1 个 commit:
    • fix(message): keep streaming cursor inside markdown
  • 只改 2 个文件:
    • Markdown.tsx
    • Message.tsx

验证结果:

  • 已 rebase 到最新 origin/main-v2
  • npx tsc --noEmit 通过,0 错误

所以现在这个 PR 可以理解为基于 #3444 之后的 cursor placement follow-up,不是和 #3444 重复的 streaming Markdown PR。

@SivanCola SivanCola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for narrowing this PR down. I still need changes before merge:

  • In Markdown.tsx, renderCursorChildren and stripSentinel unwrap every React element they encounter by returning only props.children. Because the new p/li/td/th renderers run for all Markdown, this regresses normal rendered output too: emphasis, strong text, links, inline code wrappers, task-list checkboxes, and nested list/table structure can lose their element type and props even when showCursor is false. Please preserve the original element with transformed children, for example via cloneElement, instead of returning only the descendants.

  • For an in-progress fenced code block, the appended sentinel is part of the code children. The code renderer calls stripSentinel and then renders CodeViewer without any cursor, so the streaming cursor disappears while the assistant is inside an unfinished code block. Please keep the copied/highlighted code text pure while still rendering a visible cursor in the code-block streaming state.

Reviewed/verified:

  • git diff --check origin/main-v2...origin/pr/3337 passed.
  • pnpm --dir desktop/frontend test passed.
  • pnpm --dir desktop/frontend typecheck could not complete in a clean review worktree because the generated Wails modules are absent there; the errors are outside this diff.

Once these are addressed and verification stays green, I will consider merging this into main-v2.

@SivanCola SivanCola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. I re-ran the cursor cases against the current head. The cloneElement fix moves this in the right direction, but there are still Markdown correctness regressions that need to be addressed before merge.

Comment thread desktop/frontend/src/components/Markdown.tsx Outdated
Comment thread desktop/frontend/src/components/Markdown.tsx Outdated
Comment thread desktop/frontend/src/components/Markdown.tsx Outdated
@SuMuxi66 SuMuxi66 force-pushed the fix/streaming-markdown-render branch from 7b0bf00 to 76c943e Compare June 8, 2026 10:55
@SuMuxi66

SuMuxi66 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

已经做了最新的修改了,可以审核了

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