fix(core): ignore synthetic mousemove events without coordinates in side menu - #2895
Conversation
…ide menu
A mousemove created via `new Event("mousemove")` (e.g. dispatched by a
browser extension) is a plain Event with no `clientX`/`clientY`. The
side menu's document-level listener stored the resulting `undefined`
coordinates, and `document.elementsFromPoint()` then threw
"TypeError: The provided double value is non-finite" in
`getBlockFromCoords` — including on read-only editors, since the
`isEditable` check only runs after the coordinate lookup.
Ignore mousemove events whose coordinates are not finite numbers.
|
@himself65 is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesSide menu event validation
Estimated code review effort: 1 (Trivial) | ~3 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The side menu registers a document-level capture
mousemovelistener (SideMenuView.onMouseMove) that storesevent.clientX/event.clientYverbatim. A synthetic mousemove created vianew Event("mousemove")— e.g. dispatched by a browser extension — is a plainEventwith no coordinate properties, sothis.mousePosends up as{ x: undefined, y: undefined }. The coordinates then flow throughMath.max(..., undefined)→NaNintodocument.elementsFromPoint(), which throws:Stack (from a production Sentry report, @blocknote/core 0.51.4, Chrome 150):
Note this also crashes read-only editors: the
editor.isEditablecheck inupdateStateFromMousePosruns only after the coordinate lookup.Fix
Early-return in
onMouseMovewhenclientX/clientYare not finite numbers. Sincethis.mousePoscan then never hold non-finite values, the deferredupdateStateFromMousePos()call sites (scroll / doc update) are covered as well.Testing
pnpm lintandtsgo --noEmitinpackages/core— cleanpnpm testinpackages/core— 458 passed, 3 skippedSummary by CodeRabbit