From ccac92921a1c50e7726475111bb684d31334d10d Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Tue, 22 Sep 2026 10:11:30 +0200 Subject: [PATCH] fix: avoid echoing raw app files back into the editor --- frontend/src/lib/components/raw_apps/RawAppEditor.svelte | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/lib/components/raw_apps/RawAppEditor.svelte b/frontend/src/lib/components/raw_apps/RawAppEditor.svelte index 184cca11d4..1ee3357829 100644 --- a/frontend/src/lib/components/raw_apps/RawAppEditor.svelte +++ b/frontend/src/lib/components/raw_apps/RawAppEditor.svelte @@ -794,6 +794,7 @@ } let iframeLoaded = $state(false) // @hmr:keep + let iframeFiles: Record | undefined // Briefly drops the `setActiveDocument` echo VS Code fires while we're // pushing the initial file set — the iframe auto-opens a default editor // during boot which we don't want to treat as a user-driven activation. @@ -841,6 +842,9 @@ function populateFiles() { if (files) { + // Manual edits and session autosave echoes already match the iframe. Sending them + // back can reopen its document while the user is still typing. + if (deepEqual(files, iframeFiles)) return suppressSetActiveDocument = true if (suppressTimer !== undefined) clearTimeout(suppressTimer) suppressTimer = setTimeout(() => { @@ -859,6 +863,7 @@ } } function setFilesInIframe(newFiles: Record) { + iframeFiles = { ...newFiles } const files = Object.fromEntries( Object.entries(newFiles).filter(([path, _]) => !path.endsWith('/')) ) @@ -872,6 +877,7 @@ } function setFilesAndSelectInIframe(newFiles: Record, pathToSelect: string) { + iframeFiles = { ...newFiles } iframeDocument = pathToSelect const files = Object.fromEntries( Object.entries(newFiles).filter(([path, _]) => !path.endsWith('/')) @@ -1345,6 +1351,7 @@ if (e.data.type === 'setFiles') { // Normalize Windows-style path separators to Linux-style const normalizedFiles = normalizeFilePaths(e.data.files) + iframeFiles = { ...normalizedFiles } // Only mark pending changes if files actually changed (ignore echo from setFilesInIframe) if (!deepEqual(files, normalizedFiles)) { files = normalizedFiles @@ -1961,6 +1968,7 @@ } $effect(() => { iframe?.addEventListener('load', () => { + iframeFiles = undefined iframeLoaded = true }) })