From 1959eb5920a503ab4f34e5db556838257095f5b7 Mon Sep 17 00:00:00 2001 From: Felix Gabler Date: Tue, 19 Nov 2024 03:27:06 +0100 Subject: [PATCH] fix(bubble-menu): prevent null pointer exception in `BubbleMenu` (#5842) --- .changeset/seven-hats-thank.md | 5 +++++ .../src/bubble-menu-plugin.ts | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changeset/seven-hats-thank.md diff --git a/.changeset/seven-hats-thank.md b/.changeset/seven-hats-thank.md new file mode 100644 index 000000000..8e4b671cd --- /dev/null +++ b/.changeset/seven-hats-thank.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-bubble-menu": patch +--- + +Fix a potential null pointer exception diff --git a/packages/extension-bubble-menu/src/bubble-menu-plugin.ts b/packages/extension-bubble-menu/src/bubble-menu-plugin.ts index b699079a1..d6d0428cf 100644 --- a/packages/extension-bubble-menu/src/bubble-menu-plugin.ts +++ b/packages/extension-bubble-menu/src/bubble-menu-plugin.ts @@ -266,14 +266,16 @@ export class BubbleMenuView { if (isNodeSelection(state.selection)) { let node = view.nodeDOM(from) as HTMLElement - const nodeViewWrapper = node.dataset.nodeViewWrapper ? node : node.querySelector('[data-node-view-wrapper]') - - if (nodeViewWrapper) { - node = nodeViewWrapper.firstChild as HTMLElement - } - if (node) { - return node.getBoundingClientRect() + const nodeViewWrapper = node.dataset.nodeViewWrapper ? node : node.querySelector('[data-node-view-wrapper]') + + if (nodeViewWrapper) { + node = nodeViewWrapper.firstChild as HTMLElement + } + + if (node) { + return node.getBoundingClientRect() + } } }