Skip to content

Commit 74fd724

Browse files
authored
fix: Download worker and monaco initializing multiple times in dev (#2452)
1 parent ad4205d commit 74fd724

2 files changed

Lines changed: 36 additions & 31 deletions

File tree

packages/code-studio/src/AppRoot.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { MonacoUtils } from '@deephaven/console';
33
import { DownloadServiceWorkerUtils } from '@deephaven/iris-grid';
44
import MonacoWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
@@ -11,25 +11,28 @@ if (import.meta.env.VITE_PLAYWRIGHT_CSS === '1') {
1111
}
1212

1313
export function AppRoot(): JSX.Element {
14-
DownloadServiceWorkerUtils.register(
15-
new URL(
16-
`${import.meta.env.BASE_URL ?? ''}download/serviceWorker.js`,
17-
window.location.href
18-
)
19-
);
20-
MonacoUtils.init({
21-
getWorker: (id: string, label: string) => {
22-
if (label === 'json') {
23-
return new MonacoJsonWorker();
24-
}
25-
return new MonacoWorker();
26-
},
27-
});
14+
useEffect(function init() {
15+
DownloadServiceWorkerUtils.register(
16+
new URL(
17+
`${import.meta.env.BASE_URL ?? ''}download/serviceWorker.js`,
18+
window.location.href
19+
)
20+
);
2821

29-
// disable annoying dnd-react warnings
30-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
31-
// @ts-ignore
32-
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
22+
MonacoUtils.init({
23+
getWorker: (id: string, label: string) => {
24+
if (label === 'json') {
25+
return new MonacoJsonWorker();
26+
}
27+
return new MonacoWorker();
28+
},
29+
});
30+
31+
// disable annoying dnd-react warnings
32+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
33+
// @ts-ignore
34+
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
35+
}, []);
3336

3437
return <AppRouter />;
3538
}

packages/code-studio/src/styleguide/StyleGuideRoot.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { Provider } from 'react-redux';
33
import { FontBootstrap } from '@deephaven/app-utils';
44
import '@deephaven/components/scss/BaseStyleSheet.scss';
@@ -9,18 +9,20 @@ import MonacoWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
99
import StyleGuideInit from './StyleGuideInit';
1010

1111
export function StyleGuideRoot(): JSX.Element {
12-
DownloadServiceWorkerUtils.register(
13-
new URL(
14-
`${import.meta.env.BASE_URL ?? ''}download/serviceWorker.js`,
15-
window.location.href
16-
)
17-
);
18-
MonacoUtils.init({ getWorker: () => new MonacoWorker() });
12+
useEffect(function init() {
13+
DownloadServiceWorkerUtils.register(
14+
new URL(
15+
`${import.meta.env.BASE_URL ?? ''}download/serviceWorker.js`,
16+
window.location.href
17+
)
18+
);
19+
MonacoUtils.init({ getWorker: () => new MonacoWorker() });
1920

20-
// disable annoying dnd-react warnings
21-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22-
// @ts-ignore
23-
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
21+
// disable annoying dnd-react warnings
22+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
23+
// @ts-ignore
24+
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
25+
}, []);
2426

2527
return (
2628
<FontBootstrap>

0 commit comments

Comments
 (0)