Skip to content

fix(table-core): keep columnFiltersMeta when filtering from leaf rows - #6564

Open
dylanpulver wants to merge 1 commit into
TanStack:mainfrom
dylanpulver:fix/sub-row-column-filters-meta
Open

fix(table-core): keep columnFiltersMeta when filtering from leaf rows#6564
dylanpulver wants to merge 1 commit into
TanStack:mainfrom
dylanpulver:fix/sub-row-column-filters-meta

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Aug 20, 2026

Copy link
Copy Markdown

🎯 Changes

Fixes #6074

filterRowModelFromLeafs rebuilds every row with constructRow and copies columnFilters onto the copy but not columnFiltersMeta. Since initRowInstanceData initialises both maps as empty, the meta is not undefined but silently reset to {}, so the rank metadata a filter records through addMeta is wiped and the rowA.columnFiltersMeta[columnId] guard in the fuzzy-filtering guide's sort function skips instead of throwing. This copies the meta across alongside columnFilters.

Why a per-row copy rather than inheriting or aggregating. _createFilteredRowModel already tags every row of the pre-filtered model in a flat pre-pass, so meta is computed independently at every depth: the leaf-up path loses data that exists rather than data needing derivation. Inheriting the parent's meta would stamp a parent's rank onto its sub-rows and produce wrong sort order within a group instead of a visible break. Aggregating sub-row ranks into the parent would overwrite the parent's own score, which the issue author explicitly argued against, noting a sortingFn already has row.subRows.

Nothing in table-core reads columnFiltersMeta, so restoring it cannot change any filtering, faceting, or pagination result.

Left alone deliberately: filterRowModelFromRoot clones matching parents with subRows and copies neither field, so those lose both under the default option. That path has an in-core consumer (row.columnFilters), so aligning the two is a broader decision than this bug covers. Happy to follow up separately. perf-todo.md records this gap at filterRowsUtils.ts:65 as needing "a deliberate, documented decision either way".

Tests in createFilteredRowModel.test.ts, added to the existing columnFiltersMeta describe block with a rank-scoring addMeta filter: nested rows under filterFromLeafRows: true (the retained non-matching parent keeps rank 0 rather than inheriting its child's, which pins per-row over inherited semantics), flat top-level rows under the same option, and flat rows on the default root-down path. The first two fail on main, the third passes either way.

Verified from packages/table-core: npx vitest run (63 files, 1319 passed), the changed test file (36 passed, 2 failing with the src fix stashed), npx tsc and the declaration-emit config, npx eslint ./src, and prettier --check on changed files, all clean. pnpm run test:pr is green for every lint, types, lib and build target; the only failures are the Angular example builds, which cannot run on my machine because the Angular CLI wants Node 24.15.0 and I am on 24.14.1.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Preserved column filter metadata when filtering hierarchical data from leaf rows.
    • Ensured metadata added by filter callbacks remains available on parent rows, sub-rows, and top-level rows.
    • Improved consistency between leaf-first and root-down filtering results.
  • Tests

    • Added coverage for metadata retention across matching and non-matching hierarchical filter scenarios.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1f055108-0d3f-4233-a9e5-f7ca313bb117

📥 Commits

Reviewing files that changed from the base of the PR and between 7dd6d48 and 9915384.

📒 Files selected for processing (3)
  • .changeset/quick-dryers-attend.md
  • packages/table-core/src/features/column-filtering/filterRowsUtils.ts
  • packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Leaf-first filtering now preserves each row’s columnFiltersMeta during row reconstruction. New rank-based tests cover nested rows, top-level rows, and both filtering directions. A patch changeset documents the fix.

Changes

Column filter metadata preservation

Layer / File(s) Summary
Preserve metadata during row reconstruction
packages/table-core/src/features/column-filtering/filterRowsUtils.ts
Leaf-first filtering copies columnFiltersMeta alongside columnFilters when reconstructing rows.
Validate metadata retention
packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts, .changeset/quick-dryers-attend.md
Rank-based tests cover nested and top-level rows during leaf-first and root-down filtering. The changeset documents the patch fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 99153

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

  • TanStack/table#6503: Both changes modify hierarchical filtering logic in filterRowsUtils.ts.
  • TanStack/table#6557: This change extends the same filtering fix by preserving columnFiltersMeta and adding tests.

Suggested reviewers: kevinvandy

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation copies each row’s columnFiltersMeta during leaf-up filtering and adds tests covering the requirements in issue [#6074].
Out of Scope Changes check ✅ Passed The changed implementation, tests, and patch changeset directly support issue [#6074] without unrelated code changes.
Title check ✅ Passed The title clearly and concisely describes the main fix: preserving columnFiltersMeta during leaf-row filtering.
Description check ✅ Passed The description covers the change, motivation, tests, checklist, release impact, and generated changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

filterFromLeafRows causes columnFiltersMeta to get wiped

1 participant