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]: Unexpected behaviour of configured extensions #4981

Closed
1 of 2 tasks
yurtsiv opened this issue Mar 15, 2024 · 3 comments
Closed
1 of 2 tasks

[Bug]: Unexpected behaviour of configured extensions #4981

yurtsiv opened this issue Mar 15, 2024 · 3 comments
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@yurtsiv
Copy link
Contributor

yurtsiv commented Mar 15, 2024

Which packages did you experience the bug in?

core

What Tiptap version are you using?

2.2.4

What’s the bug you are facing?

It applies to all methods in the extension config, but I'll give an example I stumbled upon with addProseMirrorPlugins

const Base = Extension.create(...)

const pluginKey = new PluginKey("someKey");

const Example = Base.extend({
  addProseMirrorPlugins() {
    return [
      ...(this.parent?.() ?? []),
      new Plugin({ key: pluginKey }),
    ]
  },
})

new Editor({
   extensions: [
      Example.configure()
   ]
})

Crashes with RangeError: Adding different instances of a keyed plugin (someKey$).

It happens because .configure() extends, so we end up with the hierarchy ExampleBase -> Example -> Example instead of ExampleBase -> Example which results in duplicate plugins being registered.

The same problem occurs with other methods, but those that return lists are most vulnerable (e.g. addInputRule).

I guess .configure() should copy the extension instead of extending it.

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

No duplicate plugins are registered.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@yurtsiv yurtsiv added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Mar 15, 2024
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap Mar 15, 2024
@yurtsiv yurtsiv changed the title [Bug]: Unexpected behaviour of this.parent() on configured extensions [Bug]: Unexpected behaviour of configured extensions Mar 15, 2024
@yurtsiv
Copy link
Contributor Author

yurtsiv commented Mar 15, 2024

Related #4704

@yurtsiv
Copy link
Contributor Author

yurtsiv commented Mar 15, 2024

This commit fda6310 seems to be the reason why it broke. Before it .extend() wasn't copying the config so the last extension in the hierarchy ExampleBase -> Example -> Example (described above) didn't have addProseMirrorPlugins and other methods defined.

Still, I believe .configure() should copy the extension instead of extending it.

@nperez0111
Copy link

This should be fixed with version 2.4.0, feel free to try it out!

@github-project-automation github-project-automation bot moved this from Triage open to Done in Tiptap May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
No open projects
Archived in project
Development

No branches or pull requests

2 participants