monaco-languageclient: [Bug] Monaco-Editor-React Fails Without Default monacoWorkerFactory
Setting up the latest @typefox/monaco-editor-react (6.6.0, and 6.7.0-next.1) leads to an issue where some workers are unavailable to the editor (editorWebWorker & textMateTokenizationWorker). Here’s a quick image of the observed errors below.
Since the modules can’t be loaded up, the whole setup appears to stop at that point. Leaving the editor intact, but without any applied highlighting or LSP functionality from an associated LS worker.
The problem appears to stem from not having the default worker factory in place for the monacoWorkerFactory config option.
const createDefaultWrapperConfig = (): WrapperConfig => {
return {
$type: "extended",
logLevel: LogLevel.Debug,
editorAppConfig: {
codeResources: {
modified: {
text: 'print("Hello, World!")',
uri: "/workspace/hello.py",
},
},
// applying the default worker factory here resolves the issue
//monacoWorkerFactory: configureDefaultWorkerFactory,
},
};
}
The addition of the monacoFactoryWorker is notably not present on the README, which means the current default setup won’t work as expected without modification. It appears that previously this worked just fine, but an upstream change looks to have broken this behavior in some way.
Associated @codingame/monaco-... packages are all at 16.0.4 for reference.
Here’s a minimal project setup using a fresh Vite + TS + React to demonstrate this using a slightly adapted version of the default Python example on the README. The issue is setup on the ‘broken-example’ branch as a heads-up, and the snippet above can be found in App.tsx.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15
Commits related to this issue
- #913 Always create a getWorker function — committed to TypeFox/monaco-languageclient by kaisalmen 2 years ago
@CGNonofr this should be in line with what you suggested: https://github.com/TypeFox/monaco-languageclient/pull/918
I think I understood the difference. When a worker is unknown, I don’t return undefined, but throw an error instead. And It makes it fallback on the mainthread impl