Skip to content

Bug: Lexical editors in multiple windows #5050

@robfig

Description

@robfig

Steps To Reproduce

I'm not sure how to make an easy reproduction, but I noticed this in our app which pops out a DOM-only Electron window. It opens a new window via window.open() and renders to it from the parent window. As a result, there are multiple window objects that can host Lexical editors and one JS environment.

The current behavior

Lexical tracks lastTextEntryTimeStamp in a way that does not account for multiple windows over the lifetime of the application. It adds an event listener to the first window and not subsequent ones.

let lastTextEntryTimeStamp = 0;

function updateTimeStamp(event) {
  lastTextEntryTimeStamp = event.timeStamp;
}

function initTextEntryListener(editor) {
  if (lastTextEntryTimeStamp === 0) {
    getWindow(editor).addEventListener("textInput", updateTimeStamp, true);
  }
}

There were a number of buggy behaviors which resulted from this, due to applying input mutations during beforeinput. The most obvious bug was the MarkdownShortcutPlugin would duplicate the closing tag.

The expected behavior

Lexical should support editors in multiple windows.

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