Skip to content

TypeError: Cannot read properties of undefined (reading 'isConnected') #2517

@Polokikim

Description

@Polokikim

What’s broken?

TypeError: Cannot read properties of undefined (reading 'isConnected') when rapidly navigating between pages while BlockNote editor is mounted.

The error occurs in the internal getBoundingClientRect wrapper function:

// @blocknote/[email protected]/dist/blocknote-react.js:158
return () => "element" in e && (e.cacheMountedBoundingClientRect ?? !0)
  ? (e.element.isConnected && (t = n()), t) : n();

The code checks "element" in e but doesn't verify e.element !== undefined before accessing .isConnected.

What did you expect to happen?

The editor should handle component unmounting gracefully without throwing errors. When the DOM element is removed during an async @floating-ui computePosition callback, the code should check if e.element is defined before accessing .isConnected.

Steps to reproduce

This is a race condition that's difficult to reproduce deterministically:

  1. Mount a BlockNote editor instance on a page
  2. Trigger a floating UI element (e.g., toolbar, suggestion menu)
  3. Rapidly navigate away from the page (unmounting the editor)
  4. The error occurs when @floating-ui's async positioning callback executes after the component unmounts

The issue is timing-dependent - the async computePosition call must be in-flight when the component unmounts.

BlockNote version

0.45.0

Environment

  • React 19 - Browser: Multiple (Chrome, Safari, Firefox based on Sentry data) - OS: Multiple platforms

Additional context

Full stack trace from Sentry:

at Object.getBoundingClientRect
@blocknote/[email protected]/dist/blocknote-react.js:158:88
at getBoundingClientRect
@floating-ui/[email protected]/dist/floating-ui.dom.mjs:87:30
at getRectRelativeToOffsetParent
@floating-ui/[email protected]/dist/floating-ui.dom.mjs:387:16
at getElementRects
@floating-ui/[email protected]/dist/floating-ui.dom.mjs:480:16
at computePosition
@floating-ui/[email protected]/dist/floating-ui.core.mjs:76:15

This is an unhandledrejection - the error bubbles up from the async computePosition call.

Contribution

  • I'd be interested in contributing a fix for this issue

Sponsor

  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖

Metadata

Metadata

Assignees

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