Skip to content

When using <FormattingToolbar>, double-clicking at end of a line causes fatal error #1115

Description

@jonathanmosney

Describe the bug
When using the <FormattingToolbar>, if the user double-clicks at end of a line, BlockNote crashes.

To Reproduce

  1. Use the FormattingToolbar, like this:
<BlockNoteView
    editor={editor}
    formattingToolbar={false}>
  <FormattingToolbar />
</BlockNoteView>
  1. Enter a few characters.
  2. Double-click at the end of the line.
  3. Note errors in the console, Blocknote unreachable. "Uncaught TypeError: Cannot read properties of undefined (reading 'type')"

Sandbox: https://stackblitz.com/edit/github-5bekpt?file=App.tsx

The issue seems to start in this function in TextAlignButton.tsx, where block === undefined, which causes checkBlockHasDefaultProp to error.

  const textAlignment = useMemo(() => {
    const block = selectedBlocks[0];

    if (checkBlockHasDefaultProp("textAlignment", block, editor)) {
      return block.props.textAlignment;
    }

    return;
  }, [editor, selectedBlocks]);

Misc

  • Node version: n/a
  • Package manager: npm
  • Browser: Chrome
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions