Skip to content

fix(components): keep newer selection when deferred table cell click fires - #2517

Open
HawkForge wants to merge 1 commit into
Milkdown:mainfrom
HawkForge:fix/table-click-stale-selection
Open

HawkForge wants to merge 1 commit into
Milkdown:mainfrom
HawkForge:fix/table-click-stale-selection

Conversation

@HawkForge

Copy link
Copy Markdown
Contributor
  • I read the contributing guide
  • I agree to follow the code of conduct

Summary

Fixes #2495. Thanks to @9BwgeBTPG-QH for the report.

TableNodeView#handleClick captured state and dispatch at click time, then dispatched state.tr.setSelection(...) later from requestAnimationFrame (or setTimeout(20) when the old selection is a CellSelection). The transaction was built from that stale state, so a selection set between the click and the callback was replaced by the click's NodeSelection.

The deferred callback now builds the transaction from view.state, and does nothing if the selection is no longer the one seen at click time. The early returns and the CellSelection branch are unchanged.

How did you test this change?

Added packages/components/src/table-block/__tests__/view.spec.ts. It stubs requestAnimationFrame, triggers the cell pointerdown, dispatches a different selection, then flushes the frame and checks the newer selection is kept. A second test checks the click still selects the cell when nothing changed in between.

  • vitest run src/table-block in packages/components: 2 passed.
  • Same run with only view.ts reverted: the first test fails (the newer selection is overwritten), the second passes.
  • vitest run in packages/components: 6 files, 32 tests passed.
  • oxlint -c .oxlintrc.json --deny-warnings and oxfmt --check on table-block: clean.

Replaces #2508, which got closed when my fork was accidentally detached.

@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2f0efa2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@milkdown/components

npm i https://pkg.pr.new/@milkdown/components@2517

@milkdown/core

npm i https://pkg.pr.new/@milkdown/core@2517

@milkdown/crepe

npm i https://pkg.pr.new/@milkdown/crepe@2517

@milkdown/ctx

npm i https://pkg.pr.new/@milkdown/ctx@2517

@milkdown/exception

npm i https://pkg.pr.new/@milkdown/exception@2517

@milkdown/kit

npm i https://pkg.pr.new/@milkdown/kit@2517

@milkdown/prose

npm i https://pkg.pr.new/@milkdown/prose@2517

@milkdown/transformer

npm i https://pkg.pr.new/@milkdown/transformer@2517

@milkdown/utils

npm i https://pkg.pr.new/@milkdown/utils@2517

@milkdown/react

npm i https://pkg.pr.new/@milkdown/react@2517

@milkdown/vue

npm i https://pkg.pr.new/@milkdown/vue@2517

@milkdown/plugin-automd

npm i https://pkg.pr.new/@milkdown/plugin-automd@2517

@milkdown/plugin-block

npm i https://pkg.pr.new/@milkdown/plugin-block@2517

@milkdown/plugin-clipboard

npm i https://pkg.pr.new/@milkdown/plugin-clipboard@2517

@milkdown/plugin-collab

npm i https://pkg.pr.new/@milkdown/plugin-collab@2517

@milkdown/plugin-cursor

npm i https://pkg.pr.new/@milkdown/plugin-cursor@2517

@milkdown/plugin-diff

npm i https://pkg.pr.new/@milkdown/plugin-diff@2517

@milkdown/plugin-emoji

npm i https://pkg.pr.new/@milkdown/plugin-emoji@2517

@milkdown/plugin-highlight

npm i https://pkg.pr.new/@milkdown/plugin-highlight@2517

@milkdown/plugin-history

npm i https://pkg.pr.new/@milkdown/plugin-history@2517

@milkdown/plugin-indent

npm i https://pkg.pr.new/@milkdown/plugin-indent@2517

@milkdown/plugin-listener

npm i https://pkg.pr.new/@milkdown/plugin-listener@2517

@milkdown/plugin-prism

npm i https://pkg.pr.new/@milkdown/plugin-prism@2517

@milkdown/plugin-slash

npm i https://pkg.pr.new/@milkdown/plugin-slash@2517

@milkdown/plugin-streaming

npm i https://pkg.pr.new/@milkdown/plugin-streaming@2517

@milkdown/plugin-tooltip

npm i https://pkg.pr.new/@milkdown/plugin-tooltip@2517

@milkdown/plugin-trailing

npm i https://pkg.pr.new/@milkdown/plugin-trailing@2517

@milkdown/plugin-upload

npm i https://pkg.pr.new/@milkdown/plugin-upload@2517

@milkdown/preset-commonmark

npm i https://pkg.pr.new/@milkdown/preset-commonmark@2517

@milkdown/preset-gfm

npm i https://pkg.pr.new/@milkdown/preset-gfm@2517

@milkdown/theme-nord

npm i https://pkg.pr.new/@milkdown/theme-nord@2517

commit: 2f0efa2

This branch has not been deployed

No deployments
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.

[Bug] Deferred table-cell click selection overwrites a newer ProseMirror selection

1 participant