fix(table-core): flatten filtered parent rows ahead of their sub-rows - #6545
fix(table-core): flatten filtered parent rows ahead of their sub-rows#6545waterWang wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthrough
ChangesFiltered flat-row ordering
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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.
🧹 Nitpick comments (1)
packages/table-core/src/features/column-filtering/filterRowsUtils.ts (1)
68-84: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid repeated
spliceoperations in leaf-first filtering.
flatIndexpoints before the recursive output. Eachsplice(flatIndex, 0, row)shifts all surviving descendants. A chain ofnrows can therefore perform O(n²) element moves.Reserve the slot before recursion, replace it with
newFilteredFlatRows[flatIndex] = row, and remove it when the parent and all descendants are discarded. This matches the root-first implementation and avoids repeated subtree shifts.Proposed change
const flatIndex = newFilteredFlatRows.length + newFilteredFlatRows.push(row) newRow.subRows = recurseFilterRows(row.subRows, depth + 1) row = newRow if (filterRow(row) && !newRow.subRows.length) { - newFilteredFlatRows.splice(flatIndex, 0, row) + newFilteredFlatRows[flatIndex] = row filteredRows.push(row) newFilteredRowsById[row.id] = row continue } if (filterRow(row) || newRow.subRows.length) { - newFilteredFlatRows.splice(flatIndex, 0, row) + newFilteredFlatRows[flatIndex] = row filteredRows.push(row) newFilteredRowsById[row.id] = row continue } + newFilteredFlatRows.pop()🤖 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/column-filtering/filterRowsUtils.ts` around lines 68 - 84, Update the leaf-first branch in recurseFilterRows to reserve flatIndex before recursing, assign the parent with newFilteredFlatRows[flatIndex] = row instead of splice, and remove the reserved slot when the parent and all descendants are discarded. Preserve the existing filteredRows and newFilteredRowsById updates while ensuring surviving descendants retain their order without repeated shifts.
🤖 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.
Nitpick comments:
In `@packages/table-core/src/features/column-filtering/filterRowsUtils.ts`:
- Around line 68-84: Update the leaf-first branch in recurseFilterRows to
reserve flatIndex before recursing, assign the parent with
newFilteredFlatRows[flatIndex] = row instead of splice, and remove the reserved
slot when the parent and all descendants are discarded. Preserve the existing
filteredRows and newFilteredRowsById updates while ensuring surviving
descendants retain their order without repeated shifts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2b28d6ec-f353-4f7b-806d-dd93abfc66d2
📒 Files selected for processing (3)
.changeset/great-pugs-sniff.mdpackages/table-core/src/features/column-filtering/filterRowsUtils.tspackages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts
🎯 Changes
getFilteredRowModel().flatRowshas the exact same post-order problem that#6529 fixed for
getSortedRowModel().flatRows.Root cause
Both
filterRowModelFromLeafs(used whenfilterFromLeafRows: true) andfilterRowModelFromRoot(default) recurse into a row's sub-rows beforepushing the row itself to
flatRows, so every descendant precedes its ownparent in the flattened list.
Fix
filterRowModelFromRoot: reserves the parent's flat-array slot beforedescending (same pattern as fix(table-core): flatten sorted parent rows ahead of their sub-rows #6529's
createSortedRowModel), then replacesit with the cloned row when recursion returns.
filterRowModelFromLeafs: records the insertion point before recursionand splices the parent ahead of its surviving children when the parent is
retained.
Before
Checklist
filterRowModelFromLeafsfixfilterRowModelFromRootfixmaxLeafRowFilterDepth: 1testthat explicitly documented the old post-order behaviour)
Closes #6536
Summary by CodeRabbit
Bug Fixes
Tests