Skip to content

Commit 5b42a7b

Browse files
committed
fix(rich-markdown-editor): seed shown-body on settled mount and track local edits
Seed lastSyncedBodyRef from a settled (non-streaming) mount and update it on local edits via onUpdate, so the streaming hold engages on the very first agent rewrite chunk (no collapse/flash) and the settle still applies the rewrite that removes a local edit.
1 parent 1149fd8 commit 5b42a7b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ export function LoadedRichMarkdownEditor({
158158
const [initialContent] = useState<JSONContent | string>(() =>
159159
streamingAtMountRef.current ? '' : parseMarkdownToDoc(splitFrontmatter(content).body)
160160
)
161+
/**
162+
* The body currently shown in the editor: seeded from a settled mount, updated on local edits (via
163+
* onUpdate) and on each streamed sync. The streaming tick reveals a chunk only when it extends this,
164+
* so an agent rewrite holds the current content instead of collapsing to a partial result.
165+
*/
166+
const lastSyncedBodyRef = useRef<string | null>(
167+
streamingAtMountRef.current ? null : splitFrontmatter(content).body
168+
)
161169
const onChangeRef = useRef(onChange)
162170
onChangeRef.current = onChange
163171
const onSaveShortcutRef = useRef(onSaveShortcut)
@@ -263,13 +271,12 @@ export function LoadedRichMarkdownEditor({
263271
},
264272
onUpdate: ({ editor }) => {
265273
const md = postProcessSerializedMarkdown(editor.getMarkdown())
274+
lastSyncedBodyRef.current = md
266275
onChangeRef.current(applyFrontmatter(settledRef.current?.frontmatter ?? '', md))
267276
},
268277
})
269278
editorInstanceRef.current = editor
270279

271-
const lastSyncedBodyRef = useRef<string | null>(null)
272-
273280
const wasStreamingRef = useRef(streamingAtMountRef.current)
274281

275282
const pendingStreamBodyRef = useRef<string | null>(null)

0 commit comments

Comments
 (0)