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 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-02-23 22:54:03 +00:00
parent 5bac8b093d
commit 7f3ddd7edd
@@ -164,10 +164,13 @@
setFilesInIframe(files)
}
}
let ignoreSetActiveDocument = false
function setFilesInIframe(newFiles: Record<string, string>) {
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') {