monaco-react: TypeError: Cannot read property 'dispose' of undefined

Hi, I’ve been playing around with your React integration of Monaco. Thanks for all your hard work in doing this!

I ran into a few problems when the editor unmounts. I’m creating the editor within a functional component and sometimes when I click something that would cause the editor to unmount (I presume), I get errors such as:

  TypeError: Cannot read property 'updateOptions' of undefined
(anonymous function)
src/afw_app/admin/node_modules/@monaco-editor/react/lib/Editor/Editor.js:166
  163 |   monacoRef.current.editor.setTheme(theme);
  164 | }, [theme]);
  165 | (0, _hooks.useUpdate)(function (_) {
> 166 |   editorRef.current.updateOptions(options);
      | ^  167 | }, [options]);
  168 | 
  169 | function createEditor() {

And:

TypeError: Cannot read property 'dispose' of undefined
removeEditor
src/afw_app/admin/node_modules/@monaco-editor/react/lib/Editor/Editor.js:182
  179 | }
  180 | 
  181 | function removeEditor() {
> 182 |   editorRef.current.dispose();
      | ^  183 | }
  184 | 
  185 | return _react["default"].createElement("section", {

I have a few other questions/comments, that I’ll leave in other open issues.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

The new version has already been published (1.0.5). @JeremyGrieshop @onatm I’ll kindly ask you to check the new version in your cases. And thank you for the help.

It’s also done for DiffEditor.

The issue has already been fixed, I’ll try to publish it today. Will keep you up to date here.

Right now the biggest problem is descriptive error messages; I’ll try to do it first.