Fix editor not rendering on every other source mode switch

This commit is contained in:
Yuri Karamian
2026-06-19 11:49:18 +02:00
parent f8371aaa57
commit 3b88b20c61
+4 -1
View File
@@ -78,6 +78,7 @@
let fixingBlobsPromise: Promise<void> = Promise.resolve(); let fixingBlobsPromise: Promise<void> = Promise.resolve();
let hasPendingBlobs = false; let hasPendingBlobs = false;
let lastSourceMode = $sourceMode; let lastSourceMode = $sourceMode;
let sourceSwapPending = false;
let linkContextMenu = $state<{ x: number; y: number; href: string; anchor: HTMLAnchorElement } | null>(null); let linkContextMenu = $state<{ x: number; y: number; href: string; anchor: HTMLAnchorElement } | null>(null);
let titleWasStripped = false; let titleWasStripped = false;
let strippedTitle = ''; let strippedTitle = '';
@@ -3327,7 +3328,7 @@
// When editorElement appears in DOM, initialize TipTap. // When editorElement appears in DOM, initialize TipTap.
// On mobile, pre-create editor with empty content so first note load is fast. // On mobile, pre-create editor with empty content so first note load is fast.
$effect(() => { $effect(() => {
if (editorElement && !editor) { if (editorElement && !editor && !sourceSwapPending) {
if (pendingContent !== null) { if (pendingContent !== null) {
createEditor(pendingContent); createEditor(pendingContent);
pendingContent = null; pendingContent = null;
@@ -4640,12 +4641,14 @@
} }
} else { } else {
// Desktop: destroy old editor, wait for DOM swap, then recreate. // Desktop: destroy old editor, wait for DOM swap, then recreate.
sourceSwapPending = true;
destroyEditor(); destroyEditor();
const content = sourceContent || ($activeNote?.content ?? ''); const content = sourceContent || ($activeNote?.content ?? '');
tick().then(() => { tick().then(() => {
if (editorElement && !editor) { if (editorElement && !editor) {
createEditor(content); createEditor(content);
} }
sourceSwapPending = false;
}); });
} }
} }