Skip to content

Commit 1ab3af9

Browse files
author
Ives van Hoorne
committed
Make worker syncing in babel-transpiler not eager.
Fixes codesandbox#1011
1 parent 76815f1 commit 1ab3af9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/app/src/sandbox/eval/transpilers/babel/worker/babel-worker.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import {
1919
} from './get-prefixed-name';
2020

2121
let fsInitialized = false;
22+
let fsLoading = false;
2223
let lastConfig = null;
2324

2425
async function initializeBrowserFS() {
26+
fsLoading = true;
2527
return new Promise(resolve => {
2628
BrowserFS.configure(
2729
{
@@ -36,6 +38,7 @@ async function initializeBrowserFS() {
3638
console.error(e);
3739
return;
3840
}
41+
fsLoading = false;
3942
fsInitialized = true;
4043
resolve();
4144
// BrowserFS is initialized and ready-to-use!
@@ -46,6 +49,12 @@ async function initializeBrowserFS() {
4649

4750
async function waitForFs() {
4851
if (!fsInitialized) {
52+
if (!fsLoading) {
53+
// We only load the fs when it's needed. The FS is expensive, as we sync all
54+
// files of the main thread to the worker. We only want to do this if it's really
55+
// needed.
56+
await initializeBrowserFS();
57+
}
4958
while (!fsInitialized) {
5059
await delay(50); // eslint-disable-line
5160
}
@@ -192,11 +201,6 @@ self.addEventListener('message', async event => {
192201
return;
193202
}
194203

195-
if (event.data.type === 'initialize-fs') {
196-
initializeBrowserFS();
197-
return;
198-
}
199-
200204
if (event.data.type === 'get-babel-context') {
201205
const transpilerOptions = event.data.babelTranspilerOptions;
202206
loadCustomTranspiler(

0 commit comments

Comments
 (0)