Skip to content

Commit 1149fd8

Browse files
committed
fix(rich-md-editor): stop the editor flashing during an agent rewrite
Only reveal streamed chunks that extend what's already shown. A divergent chunk (an agent rewrite/edit, e.g. removing appended text) would collapse the document to the partial result and flash on every chunk; now the current content is held in place and the final result is applied once on settle. Fresh writes still reveal live.
1 parent 2bbf70e commit 1149fd8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-editor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ export function LoadedRichMarkdownEditor({
291291
streamRafRef.current = null
292292
return
293293
}
294+
const shownBody = lastSyncedBodyRef.current
295+
const extendsShown = shownBody === null || pending.startsWith(shownBody)
296+
if (!extendsShown) {
297+
streamRafRef.current = null
298+
return
299+
}
294300
if (
295301
pending.length > STREAM_REPARSE_THROTTLE_THRESHOLD &&
296302
performance.now() - lastStreamParseAtRef.current < STREAM_REPARSE_THROTTLE_MS
@@ -303,7 +309,7 @@ export function LoadedRichMarkdownEditor({
303309
lastStreamParseAtRef.current = performance.now()
304310
const el = containerRef.current
305311
const pinnedToBottom = el ? el.scrollHeight - el.scrollTop - el.clientHeight < 80 : false
306-
editor.setEditable(false)
312+
if (editor.isEditable) editor.setEditable(false)
307313
editor.commands.setContent(parseMarkdownToDoc(pending), {
308314
contentType: 'json',
309315
emitUpdate: false,

0 commit comments

Comments
 (0)