Skip to content

fix(table-core): keep depth-truncated sub-rows in the leaf-up filter path - #6541

Open
lazerg wants to merge 1 commit into
TanStack:mainfrom
lazerg:fix/issue-6537-leaf-up-truncated-subrows
Open

fix(table-core): keep depth-truncated sub-rows in the leaf-up filter path#6541
lazerg wants to merge 1 commit into
TanStack:mainfrom
lazerg:fix/issue-6537-leaf-up-truncated-subrows

Conversation

@lazerg

@lazerg lazerg commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

With filterFromLeafRows: true, a row kept at maxLeafRowFilterDepth loses its whole subtree. filterRowModelFromLeafs rebuilds every row through constructRow, and once the depth cap stops the recursion the rebuilt row never gets its sub-rows back, so the descendants vanish from subRows, flatRows and rowsById at once.

// maxLeafRowFilterDepth: 1, 'keep-a1' matches at depth 1 and owns 'drop-a1a' at depth 2
table.getFilteredRowModel().rows[0].subRows[0].subRows
// before: []
// after:  [drop-a1a]

The root-down path keeps the original row instead of a rebuilt one, so its unfiltered subtree stays visible, and #6503 made those descendants join the flat arrays through addSubRowsToFlatArrays. The leaf-up path now carries the original sub-rows onto the rebuilt row and flattens them with that same helper, which #6503 listed as the remaining follow-up.

Fixes #6537

✅ Checklist

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

Two tests added to createFilteredRowModel.test.ts, mirroring the root-down ones already there for depth 0 and depth 1. Both fail on main and pass with the fix. @tanstack/table-core is at 1318/1318 tests, with eslint, types and build clean. The only red target is @tanstack/ember-table:test:lib, where testem cannot reach a local headless Chrome, and it fails the same way without this change.

🚀 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

    • Fixed hierarchical filtering when the maximum leaf-row filter depth is reached.
    • Retained rows now preserve their unfiltered descendants, including nested rows and flattened row results.
    • Row references and ordering remain consistent across filtered table results.
  • Tests

    • Added coverage for filtering at multiple depth limits, including validation of nested rows and flattened results.

@coderabbitai

coderabbitai Bot commented Aug 11, 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: b3596baa-c524-478e-bc83-fc8557c7c755

📥 Commits

Reviewing files that changed from the base of the PR and between d9cca00 and 0aa7e9b.

📒 Files selected for processing (3)
  • .changeset/leaf-up-truncated-sub-rows.md
  • packages/table-core/src/features/column-filtering/filterRowsUtils.ts
  • packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts

📝 Walkthrough

Walkthrough

The leaf-up filtering path now preserves descendants beyond maxLeafRowFilterDepth. It retains them in subRows and adds them to flatRows and rowsById. Tests cover depth values 0 and 1.

Changes

Leaf-up filtering

Layer / File(s) Summary
Preserve truncated descendants
packages/table-core/src/features/column-filtering/filterRowsUtils.ts, packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts, .changeset/leaf-up-truncated-sub-rows.md
The leaf-up filtering path retains unfiltered descendants at the maximum depth and recursively adds them to flatRows and rowsById. Tests validate depth 0 and depth 1 behavior. The changeset records the patch release.

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

Possibly related issues

Possibly related PRs

  • TanStack/table#6503 — The root-down filtering counterpart preserves unfiltered descendants beyond maxLeafRowFilterDepth.

Suggested reviewers: kevinvandy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary fix: preserving depth-truncated sub-rows in the leaf-up filtering path.
Description check ✅ Passed The description includes the change summary, completed checklist, release impact, testing results, and changeset information.
Linked Issues check ✅ Passed The implementation satisfies issue [#6537] by preserving truncated descendants and adding them to subRows, flatRows, and rowsById.
Out of Scope Changes check ✅ Passed The changeset, implementation, and targeted tests directly support the linked issue and stated filtering objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

maxLeafRowFilterDepth: leaf-up path drops truncated subRows entirely, unlike root-down after #6503

1 participant