From 83390f5ed2463557e82e14d88e5c61d324b9803c Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Fri, 19 Jun 2026 11:27:38 +0200 Subject: [PATCH] Fix images not rendering when switching back from source mode --- src/lib/components/Editor.svelte | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index 700de2f..fc4c908 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -4634,24 +4634,23 @@ } } else if (!isSource && lastSourceMode) { lastSourceMode = false; - // Both desktop and mobile: keep editor alive, just update content. - // Destroying/recreating the editor on desktop caused images not to - // render on the first switch back from source mode. const content = sourceContent || ($activeNote?.content ?? ''); - if (editor) { - ignoreNextUpdate = true; - editor.commands.setContent(markdownToHtml(content)); - // Force a re-render of images that may not load after setContent - requestAnimationFrame(() => { - if (!editor) return; - editor.view.dom.querySelectorAll('img').forEach((img) => { - const src = img.getAttribute('src'); - if (src) { - img.setAttribute('src', src); - } + // Wait for Svelte to toggle display back to the editor element, + // then update content. The editor stays alive (no destroy/recreate). + tick().then(() => { + if (editor) { + ignoreNextUpdate = true; + editor.commands.setContent(markdownToHtml(content)); + // Force image re-render for WebViews that don't trigger loads on setContent + requestAnimationFrame(() => { + if (!editor) return; + editor.view.dom.querySelectorAll('img').forEach((img) => { + const src = img.getAttribute('src'); + if (src) img.setAttribute('src', src); + }); }); - }); - } + } + }); } });