diff --git a/src/code-editor/documents/documents-load.ts b/src/code-editor/documents/documents-load.ts index 950279578..32f961992 100644 --- a/src/code-editor/documents/documents-load.ts +++ b/src/code-editor/documents/documents-load.ts @@ -75,6 +75,10 @@ editor.once('load', () => { // ready to sync doc.on('load', () => { + if (!doc.type) { + return; + } + // check if closed by the user if (!documentsIndex[id]) { return; @@ -103,7 +107,7 @@ editor.once('load', () => { if (importingAssetPath) { // Return the immediate dependencies of the asset const deps = editor.call('utils:deps-from-string', content, importingAssetPath); - const depsAsAsset = Array.from(deps).map(path => editor.call('assets:getByVirtualPath', path)); + const depsAsAsset = Array.from(deps).map(path => editor.call('assets:getByVirtualPath', path)).filter(Boolean); // And load them, ensuring that Monaco can resolve dependencies depsAsAsset.forEach(asset => loadDocument(asset, false)); diff --git a/src/code-editor/files-panel/files-panel.ts b/src/code-editor/files-panel/files-panel.ts index 793021b8c..a94aadaef 100644 --- a/src/code-editor/files-panel/files-panel.ts +++ b/src/code-editor/files-panel/files-panel.ts @@ -376,7 +376,7 @@ editor.once('load', () => { // Select file by id (which can be passed as a string or number) editor.method('files:select', (id: number|string) => { const item = idToItem.get(String(id)); - if (item) { + if (item && !item.destroyed) { tree.deselect(); item.selected = true; } diff --git a/src/code-editor/monaco/document.ts b/src/code-editor/monaco/document.ts index 9dad82a6d..1a66a7c9a 100644 --- a/src/code-editor/monaco/document.ts +++ b/src/code-editor/monaco/document.ts @@ -124,12 +124,14 @@ editor.once('load', () => { } const assetPath = asset.get('path'); - const pathAssets = assetPath.map(id => editor.call('assets:get', id)); - if (pathAssets.some(a => !a)) { - // Parent folder(s) have been deleted, skip loading - return; + const pathSegments = []; + for (const id of assetPath) { + const a = editor.call('assets:get', id); + if (!a) { + return; + } + pathSegments.push(a.get('name')); } - const pathSegments = pathAssets.map(a => a.get('name')); const path = [...pathSegments, asset.get('file').filename].join('/'); const uri = monaco.Uri.parse(`${path}`);