fix(table-core): keep columnFiltersMeta when filtering from leaf rows - #6564
fix(table-core): keep columnFiltersMeta when filtering from leaf rows#6564dylanpulver wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughLeaf-first filtering now preserves each row’s ChangesColumn filter metadata preservation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized fix preserves filter-ranking metadata when filtering from leaf rows and is covered by targeted tests; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
🎯 Changes
Fixes #6074
When
filterFromLeafRowsis enabled,filterRowModelFromLeafsrebuilds every row withconstructRowand copiescolumnFiltersonto the copy, but notcolumnFiltersMeta:columnFilteringFeature.initRowInstanceDatainitialises both maps as empty on a freshly constructedrow, so the meta is not left
undefined— it is silently reset to{}on every row in the filteredrow model. That wipes the rank metadata a filter function records through its
addMetacallback,which is exactly what the fuzzy filtering guide tells users to sort on:
The guard makes the failure silent: the meta is
{}, the branch is skipped, and rank-aware sortingquietly degrades to the fallback comparator instead of throwing. As the issue notes, this hits
top-level rows with no sub-rows too, since the leaf-up path clones unconditionally.
This copies
columnFiltersMetaacross alongsidecolumnFilters.Why a straight per-row copy, rather than inheriting or aggregating.
_createFilteredRowModeltags every row of the pre-filtered model in a flat pre-pass (
createFilteredRowModel.ts, theflatRowsloop), running the filter functions against each row's own values beforefilterRowsiscalled. So a row's meta is already computed independently at every depth — the leaf-up path is
losing data that exists, not data that needs deriving. Two alternatives were considered and
rejected:
wrong sort order within a group rather than a visible break.
parent's own score. The issue author explicitly argued against baking that into the generic
feature, noting a
sortingFnalready hasrow.subRowsif it wants that behaviour.Nothing inside
table-corereadscolumnFiltersMeta— it is a pure user-facing output surface(
createFacetedRowModelandfilterRowsImplbranch onrow.columnFilters, never on the meta), sorestoring it cannot change any filtering, faceting, or pagination result.
There is a related pre-existing asymmetry I deliberately left alone:
filterRowModelFromRootclonesmatching parent rows that have
subRowsand copies neithercolumnFiltersnorcolumnFiltersMeta,so those cloned parents lose both under the default option. That path has an in-core consumer
(
row.columnFilters), so changing it is a broader behavioural decision than this bug report covers.Happy to follow up separately if maintainers want the two paths brought in line.
Worth noting
perf-todo.mdalready records this gap atfilterRowsUtils.ts:65as pre-existingbehaviour that "must be a deliberate, documented decision either way" — this PR makes it deliberate.
Tests (
packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts,added to the existing
columnFiltersMetadescribe block, using a rank-scoringaddMetafilter inthe shape of the fuzzy docs):
filterFromLeafRows: true— meta survives on a retained sub-row, and each rowkeeps its own score: the retained non-matching parent keeps rank
0rather than inheriting itsmatching child's rank. That assertion is what pins per-row semantics over inherited ones.
filterFromLeafRows: true— covers the "even when there are no sub-rows"case from the issue.
provably confined to the leaf-up path.
The first two fail on
main(expected undefined to deeply equal { itemRank: { rank: 10 } }) andpass with the fix; the third passes both before and after.
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Context you should know before posting
bhaugeea— one-line fix, no tests. Closed 2026-08-04 byKevinVandy at the same instant as a
base_ref_deletedevent, i.e. auto-closed when its basebranch was deleted during the v9 restructure, not turned down.
ErfanBagheri404— self-closed 2026-08-16, branch deleted. No maintainerreview.
neither converted. Consider mentioning the tests early in the description.
lazerg, depth-truncated sub-rows in the leaf-uppath) and fix(table-core): flatten filtered parent rows ahead of their sub-rows #6545 (
waterWang, flatten filtered parents ahead of sub-rows). Neither touches themeta copy, but whichever lands first may cause a trivial conflict on the surrounding lines.
main: it is nowpackages/table-core/src/features/column-filtering/filterRowsUtils.ts(wassrc/utils/). Theissue and both prior PRs reference the old path.
feat-*branch names; this branch isfix/sub-row-column-filters-metaperthe task spec. Rename before pushing if you want to match their stated preference.
pages." No doc change was made — this restores documented behaviour rather than changing an API,
so there is nothing in the fuzzy-filtering guides to amend. Flagging it in case you disagree.
Local verification actually run
Run from
packages/table-coreunless noted:npx vitest run(full table-core suite)npx vitest run …/createFilteredRowModel.test.tsnpx tscnpx tsc -p tests/tsconfig.declaration-emit.jsonnpx eslint ./src(the repo'stest:eslinttarget)npx eslinton the changed test filenpx prettier --checkon all changed files (repo root)pnpm run test:pr(repo root)Files changed
packages/table-core/src/features/column-filtering/filterRowsUtils.ts— +1 line of code, +5 linesof comment explaining why the meta is copied rather than inherited or aggregated
packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts— +93 lines, three tests plus a shared rank filter fixture
.changeset/quick-dryers-attend.md— new,@tanstack/table-core: patchCommit:
9915384—fix(table-core): keep columnFiltersMeta when filtering from leaf rows,authored as
Dylan Pulver <dylanpulver@users.noreply.github.com>, no trailers.Summary by CodeRabbit
Bug Fixes
Tests