Skip to content

fix(OUT-4019): guard against stale table selection on drop - #234

Closed
priosshrsth wants to merge 1 commit into
mainfrom
anit/out-4019-rangeerror-selection-passed-to-setselection-must-point-at
Closed

fix(OUT-4019): guard against stale table selection on drop#234
priosshrsth wants to merge 1 commit into
mainfrom
anit/out-4019-rangeerror-selection-passed-to-setselection-must-point-at

Conversation

@priosshrsth

Copy link
Copy Markdown
Collaborator

Dropping content while a table cell selection is active threw RangeError: Selection passed to setSelection must point at the current document. OUT-4019 · Sentry

Root cause is upstream: prosemirror-tables' tableEditing plugin returns the current view.state.selection from its createSelectionBetween prop whenever a cell selection is active. ProseMirror's drop handler calls that prop after it has already modified the doc, then passes the stale selection to tr.setSelection — which throws. The DOM-change reader (readDOMChange) has the same shape, so this isn't drop-only, just rarer.

What to look at

  • Table.ext/table-stale-selection-guard.ts — the guard returns null when $anchor.doc === view.state.doc, which makes someProp fall through to the table plugin and leaves normal cell-selection dragging untouched. It only returns a selection when the docs differ. Confirm that read of someProp's first-non-null semantics.
  • priority: 1000 — required so this plugin is consulted before tableEditing. Worth a second pair of eyes given Tiptap reverses the extension list before sorting by priority.

Verified / not verified

Verified: pnpm typecheck and pnpm lint pass.

Not verified: no automated test. Vitest here runs environment: 'node' with no jsdom, and the two things that could actually break — plugin ordering and the ProseMirror prop contract — need a real editor to exercise. Manual repro is the check: select cells in a table, drag content, drop into the selected cell.

Regression surface is table editing generally — cell selection via mouse drag, drag-and-drop in and out of tables, and IME/composition input inside cells.

prosemirror-tables' createSelectionBetween returns view.state.selection
while a cell selection is active. Callers that resolve against an
already-modified doc (drop handler, DOM-change reader) then pass that
stale selection to tr.setSelection and hit a RangeError.

Adds a higher-priority plugin that returns a selection valid for the doc
actually being resolved against, and defers to the table plugin
otherwise.

Fixes CLIENT-HOME-V3-1M

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@linear-code

linear-code Bot commented Aug 11, 2026

Copy link
Copy Markdown

OUT-4019

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
client-home-v3 Ready Ready Preview Aug 11, 2026 5:13am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds a high-priority ProseMirror plugin that prevents the table editing plugin from returning a selection tied to the pre-change document.

  • Defers to normal table selection handling when the callback positions belong to the current view document.
  • Returns a text selection resolved against the modified document when drop or DOM-change processing creates a document mismatch.
  • Registers the guard before the table editing plugin through Tiptap extension priority.

Confidence Score: 5/5

The PR appears safe to merge; no concrete blocking or independently actionable non-blocking issues were identified.

The guard precedes the table editing plugin, defers under normal current-document selection handling, and intercepts the documented stale-document path with a selection resolved against the callback document.

Important Files Changed

Filename Overview
src/features/editor/components/Editor/extensions/Table.ext/index.ts Registers the stale-selection guard in the table extension bundle; its explicit priority gives it the intended effective plugin order.
src/features/editor/components/Editor/extensions/Table.ext/table-stale-selection-guard.ts Adds a narrowly scoped createSelectionBetween override that intercepts stale-document callbacks while preserving normal cell-selection behavior.

Reviews (1): Last reviewed commit: "fix(OUT-4019): guard against stale table..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant