From 7f3ddd7edd3ea993642aadd55cdba0ac2ea1eb9f Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Mon, 23 Feb 2026 22:54:03 +0000 Subject: [PATCH] fix: prevent iframe from overriding file selection after file creation When files change in the sidebar, setFilesInIframe sends the new files to the iframe which responds with setActiveDocument defaulting to App.tsx, overriding the user's selection. Now we ignore setActiveDocument messages for 500ms after sending setFiles to the iframe. Co-Authored-By: Claude Opus 4.6 --- frontend/src/lib/components/raw_apps/RawAppEditor.svelte | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/lib/components/raw_apps/RawAppEditor.svelte b/frontend/src/lib/components/raw_apps/RawAppEditor.svelte index 37e4be449e..112d2abd2c 100644 --- a/frontend/src/lib/components/raw_apps/RawAppEditor.svelte +++ b/frontend/src/lib/components/raw_apps/RawAppEditor.svelte @@ -164,10 +164,13 @@ setFilesInIframe(files) } } + let ignoreSetActiveDocument = false function setFilesInIframe(newFiles: Record) { const files = Object.fromEntries( Object.entries(newFiles).filter(([path, _]) => !path.endsWith('/')) ) + ignoreSetActiveDocument = true + setTimeout(() => (ignoreSetActiveDocument = false), 500) iframe?.contentWindow?.postMessage( { type: 'setFiles', @@ -612,6 +615,7 @@ } else if (e.data.type === 'updateModules') { modules = e.data.modules } else if (e.data.type === 'setActiveDocument') { + if (ignoreSetActiveDocument) return // Normalize Windows-style path separators to Linux-style selectedDocument = e.data.path?.replace(/\\/g, '/') } else if (e.data.type === 'inspectorSelect') {