Skip to content

Editor crashes with 'Illegal argument' #795

Description

@josefvegner

Describe the bug

Editor crashes with Illegal argument (internal monaco editor setValue) when editor is set as readOnly (via options) and value is changed to null.

To Reproduce

Steps to reproduce the behavior:

  1. Set Editor as readOnly via options
  2. Wait when editor is mounted and set value on Editor to null
  3. Editor crash with Illegal argument
  4. See error
Error: Illegal argument
    at ur (editor.api-CalNCsUg.js:5:866)
    at sl.setValue (editor.api-CalNCsUg.js:245:474)
    at vB.setValue (editor.api-CalNCsUg.js:257:131)
    at eval (index.mjs:11:6158)
    at Id (react-dom.min.js:165:137)
    at Xb (react-dom.min.js:200:284)
    at react-dom.min.js:197:106
    at S (react.min.js:17:25)

Root cause

On each value update Editor does not check if value is null which then cause crash with Illegal argument in monaco. Exact problem is here:

if (!editorRef.current || value === undefined) return;
if (editorRef.current.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {
  editorRef.current.setValue(value);
}

This is part from useUpdate from https://github.com/suren-atoyan/monaco-react/blob/master/src/Editor/Editor.tsx

Expected behavior

Condition should also check if value is null.

###Environment

  • monaco-editor: "0.55.1"
  • @monaco-editor/react: "4.7.0"
  • react 18

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions