fix(issues): trimEnd comparison on blur to avoid unnecessary updates (#2054)

Fixed: #2053
This commit is contained in:
ayakabot
2026-05-04 20:50:39 +08:00
committed by GitHub
parent fee393df1f
commit e13e5edc8e

View File

@@ -157,7 +157,7 @@ const ContentEditor = forwardRef<ContentEditorRef, ContentEditorProps>(
// Explicit for clarity — the real perf win is useEditorState in BubbleMenu.
shouldRerenderOnTransaction: false,
onCreate: ({ editor: ed }) => {
lastEmittedRef.current = stripBlobUrls(ed.getMarkdown());
lastEmittedRef.current = stripBlobUrls(ed.getMarkdown()).trimEnd();
},
content: defaultValue ? preprocessMarkdown(defaultValue) : "",
contentType: defaultValue ? "markdown" : undefined,
@@ -173,7 +173,7 @@ const ContentEditor = forwardRef<ContentEditorRef, ContentEditorProps>(
if (!onUpdateRef.current) return;
if (debounceRef.current) clearTimeout(debounceRef.current);
debounceRef.current = setTimeout(() => {
const md = stripBlobUrls(ed.getMarkdown());
const md = stripBlobUrls(ed.getMarkdown()).trimEnd();
if (md === lastEmittedRef.current) return;
lastEmittedRef.current = md;
onUpdateRef.current?.(md);