fix: improve row selection api performance#6344
Conversation
|
View your CI Pipeline Execution ↗ for commit 227bf9c
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughRow selection semantics now treat “some rows selected” as at least one selected row, add ChangesRow selection API update
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts (1)
246-267: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUse the matching row model for filtered/grouped selection.
Both helpers still feed
table.getCoreRowModel()intoselectRowsFn, so filtered selected models can include filtered-out rows and grouped selected models ignore the sorted/grouped pipeline even though their memo deps invalidate on those models.🐛 Proposed fix
export function table_getFilteredSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal<TFeatures, TData>) { - const rowModel = table.getCoreRowModel() + const rowModel = table.getFilteredRowModel() if ( !callMemoOrStaticFn( table, @@ export function table_getGroupedSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal<TFeatures, TData>) { - const rowModel = table.getCoreRowModel() + const rowModel = table.getSortedRowModel() if ( !callMemoOrStaticFn( table,Also applies to: 280-300
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts` around lines 246 - 267, The selection helpers are still using table.getCoreRowModel(), which bypasses the filtered/grouped pipeline and can return stale or hidden rows. Update table_getFilteredSelectedRowModel and the matching grouped-selection helper to pass the appropriate row model from the table pipeline into selectRowsFn, using the same memo/dependency path already used for filtering and grouping so the selected row model stays aligned with the current table state.
🧹 Nitpick comments (1)
packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts (1)
363-379: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid intermediate arrays in page-selection predicates.
These APIs can be hot on large pages;
filter(...).some(...)allocates where a single pass is enough.⚡ Proposed refactor
export function table_getIsAllPageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal<TFeatures, TData>) { - const paginationFlatRows = table - .getPaginatedRowModel() - .flatRows.filter((row) => row_getCanSelect(row)) + const paginationFlatRows = table.getPaginatedRowModel().flatRows const rowSelection = table.atoms.rowSelection?.get() ?? {} - let isAllPageRowsSelected = !!paginationFlatRows.length - - if ( - isAllPageRowsSelected && - paginationFlatRows.some((row) => !isRowSelected(row, rowSelection)) - ) { - isAllPageRowsSelected = false + let hasSelectableRows = false + for (const row of paginationFlatRows) { + if (!row_getCanSelect(row)) continue + hasSelectableRows = true + if (!isRowSelected(row, rowSelection)) return false } - return isAllPageRowsSelected + return hasSelectableRows } @@ export function table_getIsSomePageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal<TFeatures, TData>) { return table .getPaginatedRowModel() - .flatRows.filter((row) => row_getCanSelect(row)) - .some((row) => row_getIsSelected(row) || row_getIsSomeSelected(row)) + .flatRows.some( + (row) => + row_getCanSelect(row) && + (row_getIsSelected(row) || row_getIsSomeSelected(row)), + ) }Also applies to: 416-419
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts` around lines 363 - 379, The page-selection predicate in table_getIsAllPageRowsSelected is allocating an intermediate array via getPaginatedRowModel().flatRows.filter(...), which should be replaced with a single pass over the paginated rows; update the logic in table_getIsAllPageRowsSelected and the related page-selection check referenced by the comment (“Also applies to: 416-419”) so selection status is computed inline without filter(...).some(...) or other extra allocations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/framework/angular/guide/migrating.md`:
- Around line 680-692: The row-selection migration note currently explains the
indeterminate checkbox pattern only for table-wide selection, but it also
documents getIsSomePageRowsSelected() and should include the matching
page-scoped predicate. Update the guidance in the Row Selection API Changes
section to add the page-level formula alongside
getIsSomeRowsSelected()/getIsAllRowsSelected(), using the same style as the
existing example so page-row select-all UIs use the correct check.
In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts`:
- Around line 311-315: `table_getSelectedRowIds` is returning every key from the
row-selection state, including entries whose value is false, which can make
selected-row helpers report stale or migrated state as selected; update it to
filter by the same truthy check used by `isRowSelected` so only runtime-selected
ids are returned. Apply the same truthy-value filtering in the related
`getIsSomeRowsSelected` path as well, so both helpers stay consistent with
row-model builders and controlled state like { rowA: false } is ignored.
---
Outside diff comments:
In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts`:
- Around line 246-267: The selection helpers are still using
table.getCoreRowModel(), which bypasses the filtered/grouped pipeline and can
return stale or hidden rows. Update table_getFilteredSelectedRowModel and the
matching grouped-selection helper to pass the appropriate row model from the
table pipeline into selectRowsFn, using the same memo/dependency path already
used for filtering and grouping so the selected row model stays aligned with the
current table state.
---
Nitpick comments:
In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts`:
- Around line 363-379: The page-selection predicate in
table_getIsAllPageRowsSelected is allocating an intermediate array via
getPaginatedRowModel().flatRows.filter(...), which should be replaced with a
single pass over the paginated rows; update the logic in
table_getIsAllPageRowsSelected and the related page-selection check referenced
by the comment (“Also applies to: 416-419”) so selection status is computed
inline without filter(...).some(...) or other extra allocations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6b8d857b-7d27-4804-b1cb-03482619b12c
📒 Files selected for processing (12)
docs/framework/angular/guide/migrating.mddocs/framework/lit/guide/migrating.mddocs/framework/preact/guide/migrating.mddocs/framework/react/guide/migrating.mddocs/framework/solid/guide/migrating.mddocs/framework/svelte/guide/migrating.mddocs/framework/vue/guide/migrating.mdexamples/react/row-selection/src/main.tsxpackages/table-core/src/features/row-selection/rowSelectionFeature.tspackages/table-core/src/features/row-selection/rowSelectionFeature.types.tspackages/table-core/src/features/row-selection/rowSelectionFeature.utils.tspackages/table-core/tests/implementation/features/row-selection/rowSelectionFeature.test.ts
🎯 Changes
✅ Checklist
pnpm test:pr.Summary by CodeRabbit