Skip to content

CellMouseArgs.setActivePosition takes SetActivePositionOptions - #4258

Merged
nstepien merged 2 commits into
mainfrom
breaking/cell-mouse-args-options
Oct 31, 2026
Merged

nstepien merged 2 commits into
mainfrom
breaking/cell-mouse-args-options

Conversation

@nstepien

Copy link
Copy Markdown
Collaborator

The setActivePosition passed to onCellMouseDown, onCellClick, onCellDoubleClick, and onCellContextMenu now takes the same SetActivePositionOptions object as DataGridHandle.setActivePosition and ActiveCellKeyDownArgs.setActivePosition, instead of a positional enableEditor boolean. The three setActivePosition APIs are consistent, args.setActivePosition({ enableEditor: true }) says what it does, and mouse handlers can now pass shouldFocus, e.g., a handler that calls event.preventDefault() on mousedown to keep the browser from selecting text can still activate and focus the cell.

Breaking change

 function onCellClick(args: CellMouseArgs<Row>, event: CellMouseEvent) {
-  args.setActivePosition(true);
+  args.setActivePosition({ enableEditor: true });
 }

Affects onCellMouseDown, onCellClick, onCellDoubleClick, and onCellContextMenu handlers that call args.setActivePosition. It takes the same SetActivePositionOptions as DataGridHandle.setActivePosition, so shouldFocus is available too.

Changes

  • CellMouseArgs.setActivePosition is (options?: SetActivePositionOptions) => void. Its JSDoc now says it activates the cell, which it always did, rather than "focus", which it only does with shouldFocus.
  • Cell forwards the options unchanged to the grid's setActivePosition; the double-click default passes { enableEditor: true }, and the mousedown default passes no options, as before.
  • The README's onCellMouseDown docs mention that a handler that prevents the grid default can activate and focus the cell with args.setActivePosition({ shouldFocus: true }). The README examples, the CellMouseArgs declaration in the README, and the All Features demo use the new signature.

Verification

vp run ci passes, except for Firefox click timeouts and focus failures in 12 test files under load from other sessions' browser tests; those 12 files pass when rerun alone in Firefox. A new test in events.test.tsx calls event.preventDefault(), event.preventGridDefault(), and args.setActivePosition({ shouldFocus: true }) from onCellMouseDown, and checks that the cell is active and focused; it fails without shouldFocus. The onCellClick editor test uses { enableEditor: true }. The packed lib/index.d.ts was type-checked from a consumer file with and without exactOptionalPropertyTypes, including a @ts-expect-error on the old boolean argument.

🤖 Generated with Claude Code

The `setActivePosition` passed to cell mouse event handlers now takes the
same options object as `DataGridHandle.setActivePosition`, instead of a
positional `enableEditor` boolean, so handlers can also pass `shouldFocus`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.27%. Comparing base (5e7977b) to head (5edb18c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4258   +/-   ##
=======================================
  Coverage   99.27%   99.27%           
=======================================
  Files          44       44           
  Lines        2204     2204           
  Branches      965      964    -1     
=======================================
  Hits         2188     2188           
  Misses         16       16           
Files with missing lines Coverage Δ
src/Cell.tsx 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nstepien
nstepien marked this pull request as ready for review October 31, 2026 23:52
@nstepien
nstepien merged commit 163a071 into main Oct 31, 2026
6 checks passed
@nstepien
nstepien deleted the breaking/cell-mouse-args-options branch October 31, 2026 23:53
nstepien added a commit that referenced this pull request Nov 1, 2026
Most columns aren't frozen, and start-frozen columns are more common
than end-frozen ones, so every check of `column.frozen` now compares
against `false` first, then against `'start'`.

### Changes

- `getCellStyle`, `getCellClassname`, `getColSpan`, `collectColumns`,
and the column sort check `false` first, then `'start'`.
- `useViewportColumns` and the drag handle compare against `false`
instead of checking truthiness.
- `AGENTS.md` lists the rule under its conventions.

The normalization of `rawColumn.frozen` in `useCalculatedColumns` stays
as it is, since `undefined` is the most common value there.

Rendered markup doesn't change: `renderToString` output is
byte-identical for grids with unfrozen, start-frozen, and end-frozen
columns, with and without `colSpan`.

### Performance

The functions are faster, but whole renders don't change measurably. The
change saves about 3 ns per cell, or 1.5 µs for an update of 600 cells,
and all the code it touches is 0.2–0.5% of the CPU time of a mount or a
scroll.

Measured on the `vp pack` output with React's production build, on
Windows, for 40 columns with 1 start-frozen column. Every measurement
ran in a fresh process or page, with the order of the builds rotating
between rounds: 10 rounds in Node, 8 in Chromium, 6 in Firefox, and 4 in
WebKit. Differences are medians of the per-round differences, and a
byte-identical copy of the build usually stayed within ±2%. These runs
predate #4258, but this PR's built diff is identical to the measured
one.

Time per call, in hot loops:

| Function | Node 26 | Chromium 156 | Firefox 157 | WebKit 27.2 |
| ------------------ | -------------------: | -------------------: |
-------------------: | -------------------: |
| `getCellStyle` | 9.00 → 8.53 (−5.9%) | 9.83 → 8.71 (−11.7%) | 7.71 →
7.38 (−4.7%) | 4.12 → 3.74 (−9.6%) |
| `getCellClassname` | 65.7 → 64.4 (−2.3%) | 32.3 → 30.7 (−4.6%) | 53.3
→ 51.3 (−4.1%) | 17.8 → 17.1 (−4.5%) |

In Node, `getColSpan` went from 3.68 to 2.76 ns (−25%), sorting 40
columns from 346 to 304 ns (−12%), and `useCalculatedColumns` from 3.57
to 3.48 µs (−2.5%).

Mean render and commit time per update, in ms, without browser layout,
for 10,000 rows:

| Update | Chromium | Firefox | WebKit |
| ------------------- | ------------------: | ------------------: |
------------------: |
| Mount | 1.96 → 1.95 (−0.7%) | 5.39 → 5.31 (−1.6%) | 4.67 → 4.67
(+0.4%) |
| Vertical scroll | 2.34 → 2.35 (+0.1%) | 5.96 → 5.93 (−0.2%) | 3.27 →
3.32 (−0.1%) |
| Horizontal scroll | 1.70 → 1.69 (0.0%) | 4.06 → 4.07 (+0.4%) | 2.55 →
2.53 (+0.2%) |
| New `columns` array | 0.75 → 0.75 (−0.4%) | 2.29 → 2.30 (+0.4%) | 0.84
→ 0.87 (+4.1%) |

In Node, `renderToString` of 100 rows took 5.37 ms before and 5.40 ms
after (+1.2%), also within noise.

There's one exception. In WebKit on Windows, a new `columns` array
renders about 0.03 ms slower with these columns: +6.3%, +4.1%, and +3.9%
in three separate runs of 4, 12, and 15 rounds. With 2 start-frozen and
2 end-frozen columns, it's 1–5% faster instead. The `getCellStyle` and
`getCellClassname` changes each reproduce the slowdown, and a build with
only the other changes doesn't. The cause is unknown: it's about 50 ns
per cell, more than those two functions cost in total, so it's an
indirect effect. It only applies when `columns` changes, and Safari
wasn't tested.

`vp run ci` passes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants