TypeFox / monaco-components

Monaco Editor and Language Client Wrapper, plus Monaco Editor React Component
MIT License
42 stars 13 forks source link

Having the component twice on a page #64

Closed cdietrich closed 5 months ago

cdietrich commented 6 months ago

Hi, do you have a hint how to have the component twice on a page. am currently getting

Uncaught (in promise) Error: Services are already initialized
    at checkServicesNotInitialized (lifecycle.js:68:15)
    at initialize2 (services.js:84:5)
    at importAllServices (monaco-vscode-api-services.ts:101:11)
    at initServices (monaco-vscode-api-services.ts:29:15)
    at LanguageClientWrapper.init (languageClientWrapper.ts:93:15)
    at MonacoEditorLanguageClientWrapper.init (wrapper.ts:62:42)
kaisalmen commented 6 months ago

Hi @cdietrich did you await everything properly. There is a safe-guard for this during init. It works, see: https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/langium/wrapperStatemachine.ts

kaisalmen commented 6 months ago

... or is this working for the wrapper and not for the react component? Then this is a new issue.

cdietrich commented 6 months ago

We are using the react component yes

montymxb commented 6 months ago

@cdietrich are you using strict mode? That will trigger a 2x render, and it will make impurity issues pretty evident.

cdietrich commented 6 months ago

am not in strict mode. with having the component only once i dont see the problem

cdietrich commented 6 months ago

can also see it here in reactTs.tsx when duping the component

kaisalmen commented 6 months ago

@cdietrich seems to be a bug we need to fix. Thanks for reporting.

kaisalmen commented 5 months ago

Fixed will be contained in next release (see https://github.com/TypeFox/monaco-languageclient/pull/600) https://github.com/TypeFox/monaco-languageclient/pull/600/commits/9f49bea75114cf0785f12cb0d3bbde03d08604af

Update preview releases will come in a few minutes...

cdietrich commented 5 months ago

@kaisalmen in my example this still does not seem to work. https://github.com/cdietrich/my-monaco-editor-react-example/blob/660e1b2cd3f189bd26e9ef1804e54090f4b49e83/src/main.tsx#L7

replace this with

does show the same error

cdietrich commented 5 months ago

@kaisalmen maybe this one slipped through too

cdietrich commented 5 months ago

looks better now, but somehow the two editors seem to talk to the same language client. but maybe also problem on my side.

does not look like https://github.com/cdietrich/my-monaco-editor-react-example/tree/cd_twiceDoesStillNotWork

kaisalmen commented 5 months ago

the two editors seem to talk to the same language client. but maybe also problem on my side.

There is TypeFox/monaco-languageclient#620 that is still unresolved. If you have two editor configured with the same languageId you run into this problem.

cdietrich commented 5 months ago

thx for the heads up. a quick change of the 2nd language id does not seem to help

kaisalmen commented 5 months ago

@cdietrich ok, we need to fix/implement a solution for TypeFox/monaco-languageclient#620 I will now move all open issues to the other repo.