fix: avoid echoing raw app files back into the editor

This commit is contained in:
Guilhem Lemouel
2026-09-22 10:11:30 +02:00
parent 7d9adb3097
commit ccac92921a
@@ -794,6 +794,7 @@
}
let iframeLoaded = $state(false) // @hmr:keep
let iframeFiles: Record<string, string> | 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<string, string>) {
iframeFiles = { ...newFiles }
const files = Object.fromEntries(
Object.entries(newFiles).filter(([path, _]) => !path.endsWith('/'))
)
@@ -872,6 +877,7 @@
}
function setFilesAndSelectInIframe(newFiles: Record<string, string>, 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
})
})