react-monaco-editor / react-monaco-editor

Monaco Editor for React.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot call `editor.setValue` in `editorDidMount`

genshen opened this issue · comments

Describe the bug
I run the latest example in react-monaco-editor (8dba5e3, react-monaco-editor@0.51.0).
It can not set editor content in editorDidMount.

To Reproduce
(monaco-editor@0.34.1, react-monaco-editor@0.51.0)
Clone react-monaco-editor repo and cd the example directory. change editorDidMount in class CodeEditor to:

 editorDidMount = (editor) => {
    // eslint-disable-next-line no-console
    console.log("editorDidMount", editor, editor.getValue(), editor.getModel());
    this.editor = editor;
+    editor.setValue("// new value");
  };

The editor ui does not change to "// new value".
But if we switch to (react-monaco-editor@0.50.1 and monaco-editor@0.34.1), it works well (can show "// new value").

Expected behavior
It can show "// new value" under react-monaco-editor@0.51.0.

Screenshots/Logs

Environment (please complete the following information):

  • OS: MacOS 13.1 (22C65)

  • Browser: Firefox 108.0.1

  • Bundler: webpack

  • I will try to send a pull request to fix this issue.

Believe we're running into the same issue. Any progress?

Can also confirm react-monaco-editor@0.50.1 does not have this issue and works as expected. I would also like to point out addExtraLib doesn't work with editor.setValue in the latest version.

Believe we're running into the same issue. Any progress?

I switched to use https://github.com/suren-atoyan/monaco-react, it works well.