Skip to content

Bug: Editor constantly loses focus in React 17 #2959

Closed

Description

@hanford

When using ReactDOM.render (React 18 & 17), Having many Lexical editors with key= attributes, causes editors to lose focus in a way that becomes unusable.

This bug did not occur in Lexical 3.11 and seems to have been introduced with this commit.

I have an internal UI that's used to develop lexical that looks like this, as you're typing in the top left editor, I have a few other lexical instances with key= attributes that I forcefully re-create to ensure their instantiated with the value of the primary editor. This allows me to verify rendering is consistent across different scenarios

image

When trying to upgrade to the latest version, I noticed typing on this page stopped working, after a few hours of debugging, I narrowed it down the ReactDOM method. 🧐

The offending commit doesn't have anything that sticks out to me, but when trying my repro on the commit before it, things worked as expected, and fail afterwards.

Lexical version: 4.0 & 4.1

Steps To Reproduce

  1. Check out this sandbox
  2. Type in the top Editor, Notice that it "blurs" as soon as the onChange method is fired (this re-creates the below static editor).
  3. Toggle the ReactDOM method that's used in the index.js (enabling createRoot, disabling render)
  4. Notice you're now able to reliably type in the first editor

Link to code example: https://codesandbox.io/s/many-lexical-autofocus-forked-us0rff?file=/src/index.js

The current behavior

The editor seems to lose focus almost immediately after interacting with it

The expected behavior

Focus should remain

Activity

  1. changed the title [-]Bug: Editor constantly loses focus[/-] [+]Bug: Editor constantly loses focus in React 17[/+] on Sep 8, 2022
  2. trueadm commented on Sep 8, 2022

    @trueadm
    Collaborator

    Thanks for the detailed repro report. I found the issue and the fix should be in #2967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions