Skip to content

Close the editor when removing rows moves it to a summary row - #4248

Merged
nstepien merged 6 commits into
mainfrom
resolveposition
Oct 26, 2026
Merged

nstepien merged 6 commits into
mainfrom
resolveposition

Conversation

@nstepien

@nstepien nstepien commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

useActivePosition checks the active position on every render. It resets a position that is no longer in the grid, e.g., after a column or row is removed, and it closes the editor when its row is changed from outside. Both checks now live in resolveActivePosition, previously getResolvedValues, so resolvedActivePosition and validatedPosition are consts instead of lets reassigned through destructuring.

When rows are removed while a cell is being edited, the editor's rowIdx can land on a bottom summary row. That position is still in active bounds, but it isn't in the viewport. On main, this broke the grid in two ways:

  • getActiveRow() throws "No row for active position" during render.
  • With closeOnExternalRowChange: false, the grid never reads the row, so it stays in edit mode on the summary row, where it renders no editor. It ignores navigation keys, and the next commit, e.g., clicking another cell, throws RangeError: Invalid index from rows.with() in updateRow.

Changes

  • resolveActivePosition validates the position. When a check fails, it updates the state and calls itself with the new position. It skips the checks for the initial position, and the ACTIVE position that replaces an editor is already in bounds, so it recurses at most once.
  • The editor closes when its position isn't a cell in the viewport, whatever closeOnExternalRowChange is set to.
  • The row check reads columns[position.idx] and rows[position.rowIdx] instead of calling getActiveColumn() and getActiveRow(), which throw when the position isn't a cell, or isn't in the viewport. getActiveColumn and getActiveRow are declared after the position is resolved.
  • Two tests in renderEditCell.test.tsx remove the edited row above a bottom summary row, with and without closeOnExternalRowChange: false. Both fail on main in Chromium, Firefox, and WebKit.

React Compiler

The compiled hook uses 33 cache slots instead of 38. On main, the reassigned lets put getActiveColumn, getActiveRow, and the checks in one memo block that depends on activePosition, columns, rows, and setDraggedOverRowIdx. Now the checks have their own block, and getActiveColumn only depends on columns and the resolved position, so it keeps its identity when only rows change.

vp run ci passes.

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Oct 26, 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.13%. Comparing base (01cd99d) to head (f6235f9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4248   +/-   ##
=======================================
  Coverage   99.13%   99.13%           
=======================================
  Files          46       46           
  Lines        2192     2193    +1     
  Branches      964      966    +2     
=======================================
+ Hits         2173     2174    +1     
  Misses         19       19           
Files with missing lines Coverage Δ
src/hooks/useActivePosition.ts 96.72% <100.00%> (+0.05%) ⬆️
🚀 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 and others added 4 commits October 26, 2026 19:14
…y row

When rows are removed while a cell is being edited with
`closeOnExternalRowChange: false`, the editor can end up on a bottom
summary row. It isn't rendered there, but the grid stays in edit mode,
so it ignores navigation keys, and the next commit throws from
`rows.with()` in `updateRow`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
It updates the state when the position is no longer valid, so the
comment about reinitializing the position moves next to that check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nstepien nstepien changed the title Move the active position checks into getResolvedValues Close the editor when removing rows moves it to a summary row Oct 26, 2026
@nstepien
nstepien marked this pull request as ready for review October 26, 2026 20:19
@nstepien
nstepien merged commit 53d9d24 into main Oct 26, 2026
6 checks passed
@nstepien
nstepien deleted the resolveposition branch October 26, 2026 20:20
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