Skip to content

Commit 0b84e10

Browse files
committed
fix: code editor - workers not loading properly
1 parent 9ad475d commit 0b84e10

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ import ReactGA from 'react-ga4'
2121
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
2222
import { configureMonacoYaml } from 'monaco-yaml'
2323

24-
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
2524
import { ReactComponent as Info } from '../../Assets/Icon/ic-info-filled.svg'
2625
import { ReactComponent as ErrorIcon } from '../../Assets/Icon/ic-error-exclamation.svg'
2726
import { ReactComponent as WarningIcon } from '../../Assets/Icon/ic-warning.svg'
2827
import './codeEditor.scss'
2928
import 'monaco-editor'
3029

31-
import YamlWorker from '../../yaml.worker.js?worker'
3230
import { YAMLStringify, cleanKubeManifest, useJsonYaml } from '../Helper'
3331
import { useWindowSize } from '../Hooks'
3432
import Select from '../Select/Select'
@@ -48,10 +46,18 @@ import { MODES } from '../Constants'
4846

4947
self.MonacoEnvironment = {
5048
getWorker(_, label) {
49+
const getWorkerModule = (moduleUrl: string) => {
50+
return new Worker(self.MonacoEnvironment.getWorkerUrl(moduleUrl, label), {
51+
name: label,
52+
type: 'module',
53+
})
54+
}
55+
5156
if (label === MODES.YAML) {
52-
return new YamlWorker()
57+
return getWorkerModule('../../yaml.worker.js?worker')
5358
}
54-
return new editorWorker()
59+
60+
return getWorkerModule('/monaco-editor/esm/vs/editor/editor.worker?worker')
5561
},
5662
}
5763

@@ -73,7 +79,7 @@ function useCodeEditorContext() {
7379
* Thus as a hack we are using this objects reference to call the latest onChange reference
7480
*/
7581
const _onChange = {
76-
onChange: null
82+
onChange: null,
7783
}
7884

7985
const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.memo(

0 commit comments

Comments
 (0)