Skip to content

Commit 70cfe3c

Browse files
fix closing tabs and running initial code
1 parent 53417ba commit 70cfe3c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

packages/app/src/app/overmind/effects/preview.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ export default {
2626
}
2727
);
2828

29-
_preview.executeCodeImmediately();
30-
3129
return () => {
3230
_preview = null;
3331
dispose();
3432
};
3533
},
36-
executeCodeImmediately() {
34+
executeCodeImmediately(initialRender?: boolean) {
3735
if (!_preview) {
3836
return;
3937
}
40-
_preview.executeCodeImmediately();
38+
_preview.executeCodeImmediately(initialRender);
4139
},
4240
executeCode() {
4341
if (!_preview) {

packages/app/src/app/overmind/effects/vscode/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,22 @@ export class VSCodeEffect {
267267
);
268268
}
269269

270+
public async closeAllTabs() {
271+
if (this.editorApi) {
272+
const groupsToClose = this.editorApi.editorService.editorGroupService.getGroups();
273+
274+
await Promise.all([
275+
...groupsToClose.map(group => group.closeAllEditors()),
276+
...groupsToClose.map(group =>
277+
this.editorApi.editorService.editorGroupService.removeGroup(group)
278+
),
279+
]);
280+
}
281+
}
282+
270283
public async openModule(module: Module) {
271284
await this.initialized;
285+
272286
try {
273287
const model = await this.modelsHandler.changeModule(module);
274288

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolveModule } from '@codesandbox/common/lib/sandbox/modules';
2+
import getTemplate from '@codesandbox/common/lib/templates';
23
import {
34
EnvironmentVariable,
45
ModuleCorrection,
@@ -17,7 +18,6 @@ import {
1718
import { clearCorrectionsFromAction } from 'app/utils/corrections';
1819
import { json } from 'overmind';
1920

20-
import getTemplate from '@codesandbox/common/lib/templates';
2121
import * as internalActions from './internalActions';
2222

2323
export const internal = internalActions;
@@ -93,7 +93,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
9393
return;
9494
}
9595

96-
state.editor.isLoading = true;
96+
state.editor.isLoading = !state.editor.currentId;
9797
state.editor.notFound = false;
9898

9999
// Only reset changed modules if sandbox wasn't in memory, otherwise a fork
@@ -106,6 +106,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
106106
if (state.editor.sandboxes[newId]) {
107107
actions.internal.updateCurrentSandbox(sandbox);
108108
} else {
109+
await effects.vscode.closeAllTabs();
109110
actions.internal.setCurrentSandbox(sandbox);
110111
}
111112

@@ -129,6 +130,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
129130

130131
await effects.vscode.changeSandbox(sandbox);
131132
effects.vscode.openModule(state.editor.currentModule);
133+
effects.preview.executeCodeImmediately(true);
132134

133135
state.editor.isLoading = false;
134136
});

0 commit comments

Comments
 (0)