Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Lexical node with constructor XXXNode attempted to re-use key from node in active editor state with constructor _TextNode. #6326

Closed
milkrong opened this issue Jun 20, 2024 · 4 comments

Comments

@milkrong
Copy link

Lexical version:0.16.0

Steps To Reproduce

  1. Create a CustomerTextNode
  2. replace the Nodes as documents said

Link to code example:
https://codesandbox.io/p/sandbox/buglexical-6y7rcf

The current behavior

Always raise error: Lexical node with constructor FoxTextNode attempted to re-use key from node in active editor state with constructor _TextNode. Keys must not be re-used when the type is changed.
Why compare constructor name here? It's not make sense since my class name is defined by myself
image

The expected behavior

There is no error in the past version.

@milkrong
Copy link
Author

Is seems work if I remove replace config in node registry list. Plz update your documents if things have changed

@ivailop7
Copy link
Collaborator

When you override the node, you shouldn't pass the 'key'. Before it was silently failing, right now we just made the error visible.

@etrepum
Copy link
Collaborator

etrepum commented Jun 20, 2024

What @ivailop7 is saying is correct, people used to make this mistake and the error message happened later in a confusing place. Here you get it much sooner. Specifically this is the code that's broken:

      with: (node: TextNode) => {
        return new FoxTextNode(node.__next!, node.__key);
      },

It should be this:

      with: (node: TextNode) => {
        return new FoxTextNode(node.__text);
      },

@milkrong
Copy link
Author

What @ivailop7 is saying is correct, people used to make this mistake and the error message happened later in a confusing place. Here you get it much sooner. Specifically this is the code that's broken:

      with: (node: TextNode) => {
        return new FoxTextNode(node.__next!, node.__key);
      },

It should be this:

      with: (node: TextNode) => {
        return new FoxTextNode(node.__text);
      },

Thanks, that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants