diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index 352e963080..e8c18d17d5 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -1921,6 +1921,25 @@ }) }) + // External `code` prop changes should flow into the Monaco editor. The + // `untrack` block reads/writes Monaco without subscribing — only the + // prop read above is tracked — so the editor's own change handler + // (`updateCode`) re-running with the same value short-circuits and we + // don't loop. + $effect(() => { + const next = code ?? '' + const ed = editor + if (!ed) return + untrack(() => { + if (ed.getValue() === next) return + const model = ed.getModel() + if (!model) return + ed.pushUndoStop() + ed.executeEdits('external', [{ range: model.getFullModelRange(), text: next }]) + ed.pushUndoStop() + }) + }) + let isTsWorkerInitialized = resource([() => lang, () => initialized], async () => { if (lang !== 'typescript' || !initialized) return false // Use the stable model URI (computed once at mount), not filePath which changes on rename