fix(ui): harden issue comment editor sync

This commit is contained in:
dotta 2026-04-09 06:12:43 -05:00
parent 996c7eb727
commit 327eadb45c
4 changed files with 59 additions and 2 deletions

View file

@ -364,6 +364,19 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
return map;
}, [mentions]);
const setEditorRef = useCallback((instance: MDXEditorMethods | null) => {
ref.current = instance;
if (!instance) {
return;
}
if (valueRef.current !== latestValueRef.current) {
// Re-apply the latest controlled value once MDXEditor exposes its imperative API.
echoIgnoreMarkdownRef.current = valueRef.current;
instance.setMarkdown(valueRef.current);
latestValueRef.current = valueRef.current;
}
}, []);
const filteredMentions = useMemo<AutocompleteOption[]>(() => {
if (!mentionState) return [];
const q = mentionState.query.trim().toLowerCase();
@ -798,7 +811,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
onPasteCapture={handlePasteCapture}
>
<MDXEditor
ref={ref}
ref={setEditorRef}
markdown={value}
placeholder={placeholder}
onChange={(next) => {