fix(webcontainer): prevent double initialization and race conditions when booting WebContainer and loading editor workspace/file tree
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user