fix(webcontainer): prevent double initialization and race conditions when booting WebContainer and loading editor workspace/file tree

This commit is contained in:
2025-12-30 15:47:15 +00:00
parent 26759a5b90
commit c27b532aaa
6 changed files with 63 additions and 9 deletions

View File

@@ -55,6 +55,7 @@ export class DeesEditorFiletree extends DeesElement {
accessor errorMessage: string = '';
private expandedPaths: Set<string> = new Set();
private loadTreeStarted: boolean = false;
public static styles = [
themeDefaultStyles,
@@ -484,6 +485,10 @@ export class DeesEditorFiletree extends DeesElement {
private async loadTree() {
if (!this.executionEnvironment) return;
// Prevent double loading on initial render
if (this.loadTreeStarted) return;
this.loadTreeStarted = true;
this.isLoading = true;
this.errorMessage = '';
@@ -503,6 +508,8 @@ export class DeesEditorFiletree extends DeesElement {
} catch (error) {
this.errorMessage = `Failed to load files: ${error}`;
console.error('Failed to load file tree:', error);
// Reset flag to allow retry
this.loadTreeStarted = false;
} finally {
this.isLoading = false;
}
@@ -521,6 +528,7 @@ export class DeesEditorFiletree extends DeesElement {
public async refresh() {
this.expandedPaths.clear();
this.loadTreeStarted = false; // Reset to allow loading
await this.loadTree();
}

View File

@@ -74,6 +74,7 @@ export class DeesEditorWorkspace extends DeesElement {
accessor isInitializing: boolean = true;
private editorElement: DeesEditorMonaco | null = null;
private initializationStarted: boolean = false;
public static styles = [
themeDefaultStyles,
@@ -442,6 +443,10 @@ export class DeesEditorWorkspace extends DeesElement {
private async initializeWorkspace() {
if (!this.executionEnvironment) return;
// Prevent double initialization
if (this.initializationStarted) return;
this.initializationStarted = true;
this.isInitializing = true;
try {
@@ -450,6 +455,8 @@ export class DeesEditorWorkspace extends DeesElement {
}
} catch (error) {
console.error('Failed to initialize workspace:', error);
// Reset flag to allow retry
this.initializationStarted = false;
} finally {
this.isInitializing = false;
}