Skip to content

Commit ff3883a

Browse files
fix(web): stop remounting markdown on every activity delta
MessagesTimeline's shared row state built a fresh threadRef object each time it recomputed, which happens on every activity delta while a thread is working. ChatMarkdown keys its react-markdown component map on that threadRef, so a new identity replaced every renderer's element type and React remounted the whole rendered markdown subtree of each visible assistant message. That destroyed the DOM nodes under any native text selection, so the "cite" toolbar dropped within a second on working threads. Reuse the memoized citationThreadRef so the prop stays stable and ChatMarkdown's memo bails out. Co-Authored-By: Claude Code <[email protected]>
1 parent ca63d42 commit ff3883a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ export const MessagesTimeline = memo(function MessagesTimeline({
626626
listRef,
627627
timestampFormat,
628628
routeThreadKey,
629-
threadRef: parseScopedThreadKey(routeThreadKey),
629+
// Must be referentially stable: ChatMarkdown keys its react-markdown
630+
// component map on threadRef, and a fresh object here remounts every
631+
// rendered markdown node whenever this memo recomputes (e.g. on each
632+
// activity delta while the thread is working).
633+
threadRef: citationThreadRef,
630634
markdownCwd,
631635
resolvedTheme,
632636
workspaceRoot,
@@ -650,6 +654,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
650654
listRef,
651655
timestampFormat,
652656
routeThreadKey,
657+
citationThreadRef,
653658
markdownCwd,
654659
resolvedTheme,
655660
workspaceRoot,

0 commit comments

Comments
 (0)