-
-
Notifications
You must be signed in to change notification settings - Fork 698
Description
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:
- Mount a BlockNote editor instance on a page
- Trigger a floating UI element (e.g., toolbar, suggestion menu)
- Rapidly navigate away from the page (unmounting the editor)
- 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 💖