Skip to content

[Bug]: Bubble Menu resize event is not cleaned up when removed #6446

Closed
@NervosaX

Description

@NervosaX

Affected Packages

extension-bubble-menu

Version(s)

3.0.0-beta.7

Bug Description

I'm creating and destroying bubble menus for my current project, and I've noticed it's trying to run code on destroyed editors, and it consistently increases the more I load up a new editor.

Looking at the code I can see why https://github.com/ueberdosis/tiptap/blob/next/packages/extension-bubble-menu/src/bubble-menu-plugin.ts#L233

The bubble menu resize handler is being added but never removed on plugin removal. To work around it I've extended the class and done the following:

class MyBubbleMenuView extends BubbleMenuView {
	constructor(...args) {
		const origListener = window.addEventListener;
		window.addEventListener = () => {};
		super(...args);
		window.addEventListener = origListener;
		window.addEventListener("resize", this.onResize);
	}

	onResize = () => {
		if (this.resizeDebounceTimer) {
			clearTimeout(this.resizeDebounceTimer);
		}

		this.resizeDebounceTimer = window.setTimeout(() => {
			this.updatePosition();
		}, this.resizeDelay);
	};

	destroy() {
		super.destroy();
		window.removeEventListener("resize", this.onResize);
	}
}

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

The resize event should not be called after the plugin is destroyed.

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Category: Open SourceThe issue or pull reuqest is related to the open source packages of Tiptap.Type: BugThe issue or pullrequest is related to a bug

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions