Fix editor not rendering on every other source mode switch

This commit is contained in:
Yuri Karamian
2026-06-19 11:47:11 +02:00
parent c5a45131a5
commit f8371aaa57
+9 -7
View File
@@ -3392,7 +3392,15 @@
function createEditor(content: string) { function createEditor(content: string) {
if (!editorElement) return; if (!editorElement) return;
destroyEditor(); // Don't call destroyEditor here — it sets editorReady=false which
// triggers reactivity and races with the tick().then() in the
// source-mode swap. Just destroy the editor instance directly.
if (editor) {
editor.destroy();
editor = null;
}
mathObserver?.disconnect();
mathObserver = null;
isLargeDoc = content.length > LARGE_DOC_CHARS; isLargeDoc = content.length > LARGE_DOC_CHARS;
const html = markdownToHtml(content); const html = markdownToHtml(content);
@@ -4616,11 +4624,6 @@
// Only act if we have a loaded note // Only act if we have a loaded note
if (!loadedPath) return; if (!loadedPath) return;
// untrack: prevent flushSave() (inside destroyEditor) from adding
// $editorDirty/$activeNote as effect dependencies, which causes
// the effect to re-run and race with tick().then() — resulting in
// the editor failing to render on every other source-mode switch.
untrack(() => {
if (isSource && !lastSourceMode) { if (isSource && !lastSourceMode) {
// Switching TO source: extract markdown from editor // Switching TO source: extract markdown from editor
sourceContent = editor ? editorToMarkdown() : ($activeNote?.content ?? ''); sourceContent = editor ? editorToMarkdown() : ($activeNote?.content ?? '');
@@ -4647,7 +4650,6 @@
} }
} }
}); });
});
// Tauri drag-drop listener for OS file drops (browser DragEvent doesn't have files in Tauri) // Tauri drag-drop listener for OS file drops (browser DragEvent doesn't have files in Tauri)
let unlistenDragDrop: (() => void) | null = null; let unlistenDragDrop: (() => void) | null = null;