Skip to content

Commit 7a1379b

Browse files
clean FS on changing sandbox, improve create LIVE experience
1 parent 0c24a4d commit 7a1379b

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class SandboxFsSync {
7272
public dispose() {
7373
this.isDisposed = true;
7474
self.removeEventListener('message', this.onWorkerMessage);
75+
this.clearSandboxFiles();
7576
}
7677

7778
public create(sandbox: Sandbox): SandboxFs {
@@ -401,6 +402,29 @@ class SandboxFsSync {
401402

402403
return files;
403404
}
405+
406+
private clearSandboxFiles(dir = '/sandbox') {
407+
if (dir === '/sandbox/node_modules') {
408+
return;
409+
}
410+
411+
const kids = browserFs.readdirSync(dir);
412+
413+
kids.forEach(kid => {
414+
const path = join(dir, kid);
415+
const lstat = browserFs.lstatSync(path);
416+
417+
if (lstat.isDirectory()) {
418+
this.clearSandboxFiles(path);
419+
} else {
420+
browserFs.unlinkSync(path);
421+
}
422+
});
423+
424+
if (dir !== '/sandbox') {
425+
browserFs.rmdirSync(dir);
426+
}
427+
}
404428
}
405429

406430
export default SandboxFsSync;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ export const forkSandbox: AsyncAction<{
345345
forkedSandbox
346346
);
347347
effects.preview.updateAddressbarUrl();
348-
actions.workspace.openDefaultItem();
348+
349+
if (state.workspace.openedWorkspaceItem === 'project-summary') {
350+
actions.workspace.openDefaultItem();
351+
}
352+
349353
effects.notificationToast.success('Forked sandbox!');
350354
effects.router.updateSandboxUrl(forkedSandbox);
351355
} catch (error) {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ export const createLiveClicked: AsyncAction<{
4242
}> = async ({ state, effects, actions }, { sandboxId }) => {
4343
effects.analytics.track('Create Live Session');
4444

45-
await effects.vscode.closeAllTabs();
46-
4745
const roomId = await effects.api.createLiveRoom(sandboxId);
4846
const sandbox = await actions.live.internal.initialize(roomId);
49-
actions.internal.setCurrentSandbox(sandbox);
5047

51-
await effects.vscode.changeSandbox(state.editor.currentSandbox, fs => {
52-
state.editor.modulesByPath = fs;
48+
Object.assign(sandbox, {
49+
modules: sandbox.modules.map(module => ({
50+
...module,
51+
code: state.editor.currentSandbox.modules.find(
52+
currentSandboxModule => currentSandboxModule.shortid === module.shortid
53+
).code,
54+
})),
5355
});
5456

55-
effects.vscode.openModule(state.editor.currentModule);
56-
effects.preview.executeCodeImmediately({ initialRender: true });
57+
Object.assign(state.editor.sandboxes[state.editor.currentId], sandbox);
58+
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(sandbox);
5759
};
5860

5961
export const liveMessageReceived: Operator<LiveMessage> = pipe(

standalone-packages/codesandbox-browserfs/src/backend/CodeSandboxEditorFS.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ export default class CodeSandboxEditorFS extends SynchronousFileSystem
291291
// Stubbed
292292
}
293293

294+
public unlinkSync(p: string) {
295+
// Stubbed
296+
}
297+
294298
public readdirSync(path: string): string[] {
295299
const paths = Object.keys(this.api.getSandboxFs());
296300

0 commit comments

Comments
 (0)