monaco-languageclient icon indicating copy to clipboard operation
monaco-languageclient copied to clipboard

MonacoEditorReactComp not fires onTextChanged callback if you change code resource

Open lobotomoe opened this issue 1 year ago • 5 comments

I try to use @typefox/monaco-editor-react with multiple files, but only for first file callback onTextChanged fired.

Repro repo: https://github.com/lobotomoe/monaco-on-text-changed-issue

Steps for repro:

  • git clone
  • npm i
  • npm run dev

Try to type something and you will see in console that onTextChanged fired. Switch to second file. Try to type — nothing happens. Switch back to first file, try to type — callback fires.

See video demo:

https://github.com/TypeFox/monaco-languageclient/assets/24254622/db412849-45a4-475b-a38c-a141079c65a7

lobotomoe avatar Jul 02 '24 15:07 lobotomoe

HI @lobotomoe thank you for reporting this and providing a re-producible example. We will investigate...

kaisalmen avatar Jul 02 '24 16:07 kaisalmen

@lobotomoe the file changes are not provoking componentDidUpdate in MonacoEditorReact . The whole evaluation internally is based on UserConfig comparison which decides if the underlying wrapper/editor needs to be restart or just reconfigured. But there is no simple trigger. Currently, you can create a ref to -MonacoEditorReactComp and then trigger the update directly on the underlying wrapper. Maybe we should add a boolean property to the MonacoEditorProps, so they can easily trigger a re-evaluation of the status?

kaisalmen avatar Jul 14 '24 11:07 kaisalmen

@kaisalmen Thanks for the answer! I'm not sure if it's worth bothering so much purely because of my case, but I don't mind if there's a flag 😀

Currently I'll try your approach with ref and manual trigger

lobotomoe avatar Jul 14 '24 12:07 lobotomoe

@lobotomoe we want to transform the ClassComponent to a FunctionalComponent and when we will do it think about this use case. Another possibility I forgot about is that onLoad() gives you the wrapper and when you have that you can do everything, see: https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/src/python/client/reactPython.tsx#L44-L46

kaisalmen avatar Jul 15 '24 13:07 kaisalmen

@lobotomoe #739 is merged, but not yet released. It will take some time because it will be a major version and there are other things that should be included as well.

I will take a look if we can build a unit test for this problem now...

kaisalmen avatar Aug 30 '24 13:08 kaisalmen

@lobotomoe can you try the latest preview build: https://www.npmjs.com/package/@typefox/monaco-editor-react/v/6.0.0-next.5 ?

kaisalmen avatar Oct 25 '24 13:10 kaisalmen

v6 is available. No feedback was provided. No longer considered an issue.

kaisalmen avatar Jan 23 '25 19:01 kaisalmen