mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
Merge pull request #309 from thecodacus/fix-project-reload-execution-order
fix(project-reload): execution order is fix, this fixes the inconsistency on project reload
This commit is contained in:
commit
87e9fc7d39
@ -94,7 +94,7 @@ export class ActionRunner {
|
|||||||
|
|
||||||
this.#updateAction(actionId, { ...action, ...data.action, executed: !isStreaming });
|
this.#updateAction(actionId, { ...action, ...data.action, executed: !isStreaming });
|
||||||
|
|
||||||
this.#currentExecutionPromise = this.#currentExecutionPromise
|
return this.#currentExecutionPromise = this.#currentExecutionPromise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.#executeAction(actionId, isStreaming);
|
return this.#executeAction(actionId, isStreaming);
|
||||||
})
|
})
|
||||||
@ -119,7 +119,14 @@ export class ActionRunner {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'start': {
|
case 'start': {
|
||||||
await this.#runStartAction(action)
|
// making the start app non blocking
|
||||||
|
|
||||||
|
this.#runStartAction(action).then(()=>this.#updateAction(actionId, { status: 'complete' }))
|
||||||
|
.catch(()=>this.#updateAction(actionId, { status: 'failed', error: 'Action failed' }))
|
||||||
|
// adding a delay to avoid any race condition between 2 start actions
|
||||||
|
// i am up for a better approch
|
||||||
|
await new Promise(resolve=>setTimeout(resolve,2000))
|
||||||
|
return
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ export class WorkbenchStore {
|
|||||||
modifiedFiles = new Set<string>();
|
modifiedFiles = new Set<string>();
|
||||||
artifactIdList: string[] = [];
|
artifactIdList: string[] = [];
|
||||||
#boltTerminal: { terminal: ITerminal; process: WebContainerProcess } | undefined;
|
#boltTerminal: { terminal: ITerminal; process: WebContainerProcess } | undefined;
|
||||||
|
#globalExecutionQueue=Promise.resolve();
|
||||||
constructor() {
|
constructor() {
|
||||||
if (import.meta.hot) {
|
if (import.meta.hot) {
|
||||||
import.meta.hot.data.artifacts = this.artifacts;
|
import.meta.hot.data.artifacts = this.artifacts;
|
||||||
@ -52,6 +52,10 @@ export class WorkbenchStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addToExecutionQueue(callback: () => Promise<void>) {
|
||||||
|
this.#globalExecutionQueue=this.#globalExecutionQueue.then(()=>callback())
|
||||||
|
}
|
||||||
|
|
||||||
get previews() {
|
get previews() {
|
||||||
return this.#previewsStore.previews;
|
return this.#previewsStore.previews;
|
||||||
}
|
}
|
||||||
@ -255,8 +259,11 @@ export class WorkbenchStore {
|
|||||||
|
|
||||||
this.artifacts.setKey(messageId, { ...artifact, ...state });
|
this.artifacts.setKey(messageId, { ...artifact, ...state });
|
||||||
}
|
}
|
||||||
|
addAction(data: ActionCallbackData) {
|
||||||
async addAction(data: ActionCallbackData) {
|
this._addAction(data)
|
||||||
|
// this.addToExecutionQueue(()=>this._addAction(data))
|
||||||
|
}
|
||||||
|
async _addAction(data: ActionCallbackData) {
|
||||||
const { messageId } = data;
|
const { messageId } = data;
|
||||||
|
|
||||||
const artifact = this.#getArtifact(messageId);
|
const artifact = this.#getArtifact(messageId);
|
||||||
@ -265,10 +272,18 @@ export class WorkbenchStore {
|
|||||||
unreachable('Artifact not found');
|
unreachable('Artifact not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
artifact.runner.addAction(data);
|
return artifact.runner.addAction(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async runAction(data: ActionCallbackData, isStreaming: boolean = false) {
|
runAction(data: ActionCallbackData, isStreaming: boolean = false) {
|
||||||
|
if(isStreaming) {
|
||||||
|
this._runAction(data, isStreaming)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.addToExecutionQueue(()=>this._runAction(data, isStreaming))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async _runAction(data: ActionCallbackData, isStreaming: boolean = false) {
|
||||||
const { messageId } = data;
|
const { messageId } = data;
|
||||||
|
|
||||||
const artifact = this.#getArtifact(messageId);
|
const artifact = this.#getArtifact(messageId);
|
||||||
@ -293,11 +308,11 @@ export class WorkbenchStore {
|
|||||||
this.#editorStore.updateFile(fullPath, data.action.content);
|
this.#editorStore.updateFile(fullPath, data.action.content);
|
||||||
|
|
||||||
if (!isStreaming) {
|
if (!isStreaming) {
|
||||||
this.resetCurrentDocument();
|
|
||||||
await artifact.runner.runAction(data);
|
await artifact.runner.runAction(data);
|
||||||
|
this.resetAllFileModifications();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
artifact.runner.runAction(data);
|
await artifact.runner.runAction(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user