Skip to content

Commit 00cd56e

Browse files
christianalfoniCompuIves
authored andcommitted
Initialize an initial sandbox fs sync (codesandbox#3145)
1 parent 50ca9e1 commit 00cd56e

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
import { isAbsoluteVersion } from '@codesandbox/common/lib/utils/dependencies';
1515
import { getGlobal } from '@codesandbox/common/lib/utils/global';
1616
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
17+
import { getSavedCode } from 'app/overmind/utils/sandbox';
1718
import { json } from 'overmind';
1819

19-
import { getSavedCode } from 'app/overmind/utils/sandbox';
2020
import { WAIT_INITIAL_TYPINGS_MS } from '../constants';
2121
import { appendFile, mkdir, rename, rmdir, unlink, writeFile } from './utils';
2222

@@ -286,15 +286,15 @@ class SandboxFsSync {
286286
try {
287287
browserFs.stat('/sandbox/package.json', (packageJsonError, stat) => {
288288
if (packageJsonError) {
289-
reject(packageJsonError);
289+
resolve(null);
290290
return;
291291
}
292292

293293
browserFs.readFile(
294294
'/sandbox/package.json',
295295
async (packageJsonReadError, rv) => {
296296
if (packageJsonReadError) {
297-
reject(packageJsonReadError);
297+
resolve(null);
298298
return;
299299
}
300300

@@ -417,12 +417,17 @@ class SandboxFsSync {
417417

418418
kids.forEach(kid => {
419419
const path = join(dir, kid);
420-
const lstat = browserFs.lstatSync(path);
421420

422-
if (lstat.isDirectory()) {
423-
this.clearSandboxFiles(path);
424-
} else {
425-
browserFs.unlinkSync(path);
421+
try {
422+
const lstat = browserFs.lstatSync(path);
423+
424+
if (lstat.isDirectory()) {
425+
this.clearSandboxFiles(path);
426+
} else {
427+
browserFs.unlinkSync(path);
428+
}
429+
} catch {
430+
// Do nothing
426431
}
427432
});
428433

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import prettify from 'app/src/app/utils/prettify';
1919
import { blocker } from 'app/utils/blocker';
2020
import { listen } from 'codesandbox-api';
2121
import FontFaceObserver from 'fontfaceobserver';
22+
import { debounce } from 'lodash-es';
2223
import * as childProcess from 'node-services/lib/child_process';
2324

24-
import { debounce } from 'lodash-es';
2525
import { EXTENSIONS_LOCATION, VIM_EXTENSION_ID } from './constants';
2626
import {
27-
initializeCustomTheme,
2827
initializeCodeSandboxTheme,
28+
initializeCustomTheme,
2929
initializeExtensionsFolder,
3030
initializeSettings,
3131
initializeThemeCache,
@@ -120,6 +120,13 @@ export class VSCodeEffect {
120120

121121
this.prepareElements();
122122

123+
// We instantly create a sandbox sync, as we want our
124+
// extension host to get its messages handled to initialize
125+
// correctly
126+
this.sandboxFsSync = new SandboxFsSync({
127+
getSandboxFs: () => ({}),
128+
});
129+
123130
import(
124131
// @ts-ignore
125132
'worker-loader?publicPath=/&name=ext-host-worker.[hash:8].worker.js!./extensionHostWorker/bootstrappers/ext-host'
@@ -285,8 +292,6 @@ export class VSCodeEffect {
285292
public async changeSandbox(sandbox: Sandbox, setFs: (fs: SandboxFs) => void) {
286293
await this.initialized;
287294

288-
const isFirstSync = !this.sandboxFsSync;
289-
290295
if (this.modelsHandler) {
291296
this.modelsHandler.dispose();
292297
}
@@ -306,15 +311,10 @@ export class VSCodeEffect {
306311

307312
setFs(this.sandboxFsSync.create(sandbox));
308313

309-
// We do not stop the extension host on first sync
310-
if (isFirstSync) {
311-
this.sandboxFsSync.sync(() => {});
312-
} else {
313-
this.editorApi.extensionService.stopExtensionHost();
314-
this.sandboxFsSync.sync(() => {
315-
this.editorApi.extensionService.startExtensionHost();
316-
});
317-
}
314+
this.editorApi.extensionService.stopExtensionHost();
315+
this.sandboxFsSync.sync(() => {
316+
this.editorApi.extensionService.startExtensionHost();
317+
});
318318
}
319319

320320
public async setModuleCode(module: Module) {

0 commit comments

Comments
 (0)