Skip to content

Bug: LexicalEditorRefPlugin crashes if input is null #8327

@Jimmy89

Description

@Jimmy89

Lexical version: 0.42.0 (but the bug is detected in the main branch as well)

Steps To Reproduce

  1. Mount Lexical with EditorRefPlugin attached, but without actually providing a ref
  2. Error occurs on this line

Link to code example:

(function ReactComponent(props) {
const ref = null;
// react component with lexical
        <EditorRefPlugin editorRef={ref}/> // where ref is `null`
});

The current behavior

While the typescript docs mention null as input parameter
the typeof editorRef === "object" is missing a && editorRef !== null part.

The expected behavior

No crash on editorRef.current = editor; when editorRef === null

Impact of fix

Adding the null check fixes everything ;)
My current workaround
<EditorRefPlugin editorRef={ref || undefined }/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions