Skip to content

perf(desktop): use useDeferredValue in Markdown#2953

Open
HUQIANTAO wants to merge 1 commit into
esengine:main-v2from
HUQIANTAO:pr/debounce-markdown
Open

perf(desktop): use useDeferredValue in Markdown#2953
HUQIANTAO wants to merge 1 commit into
esengine:main-v2from
HUQIANTAO:pr/debounce-markdown

Conversation

@HUQIANTAO
Copy link
Copy Markdown
Contributor

Wrap Markdown text in useDeferredValue so React prioritises input/scroll over expensive markdown parse during the streaming→complete transition.

…long renders

The Markdown component parses and renders the full text synchronously via
react-markdown. For very long assistant responses (e.g. a multi-page code
explanation with tables and math), this can block the main thread for 50-100ms
during the final markdown pass after streaming completes.

Wrap the text input in useDeferredValue so React can:
1. Prioritise the plain-text streaming frame (which is already fast)
2. Abort an in-progress markdown render if a new delta arrives
3. Yield to high-priority updates (scroll, input) during the parse

This is especially effective for the transition from streaming (plain text)
to complete (markdown): the deferred value lets React start the markdown
parse in the background while keeping the cursor and scroll responsive.
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant