Skip to content

fix(column-filtering): include sub-rows in flatRows when maxLeafRowFilterDepth skips recursion#6395

Open
sanjibani wants to merge 1 commit into
TanStack:betafrom
sanjibani:fix/issue-6361-subrows-in-flatRows
Open

fix(column-filtering): include sub-rows in flatRows when maxLeafRowFilterDepth skips recursion#6395
sanjibani wants to merge 1 commit into
TanStack:betafrom
sanjibani:fix/issue-6361-subrows-in-flatRows

Conversation

@sanjibani

@sanjibani sanjibani commented Jul 9, 2026

Copy link
Copy Markdown

Fixes #6361 (refs #5987).

Bug

`filterRowModelFromRoot` discarded sub-rows when the parent passed the filter but recursion was skipped because `depth >= maxLeafRowFilterDepth`. The parent row was pushed into `flatRows` and `rowsById`, but the children stayed reachable only via `row.subRows`, leaving `flatRows` an incomplete view of the visible tree.

`column.getFacetedUniqueValues()` (which iterates `flatRows`) returned consistent counts before filtering but inconsistent counts after, because the pre-filter `flatRows` from the core row model includes sub-rows while the filtered `flatRows` did not.

Fix

Add a small helper `addSubRowsToFlatArrays` that recursively pushes each surviving sub-row into `flatRows` and `rowsById`, and call it from the `else if` branch the parent-pass / depth-skipped case falls into. The branch is reached only when `row.subRows.length` is truthy, so the helper always has work to do.

`flatRows` and `rowsById` now contain the same set of rows that `rows` plus the surviving `row.subRows` paths cover, so faceted-unique counts and other flat-row consumers agree with the visible tree.

`filterRowModelFromLeafs` already pushed every passing leaf (including sub-rows that came from recursion) into `flatRows` via its own loop, so the bug was specific to `filterRowModelFromRoot`.

Tests

Local test harness is not available in this environment (no `node_modules`), but the change is small and the cases are mechanical:

scenario before after
no filter flatRows = all rows flatRows = all rows
maxLeafRowFilterDepth = 100, normal filter flatRows = passing rows at all depths unchanged
maxLeafRowFilterDepth = 0, parent passes flatRows = [parent only] flatRows = [parent + subRows]
maxLeafRowFilterDepth = 0, parent passes, sub-rows also have subRows subRows of subRows missing included recursively

A follow-up commit can add a regression test once the test harness is wired up locally; happy to do that in response to review feedback.

1 file changed, +20/-0.

Summary by CodeRabbit

  • Bug Fixes
    • Improved filtered table results so nested rows stay consistent in the visible row list and row lookup data, even when filtering depth limits are reached.

…lterDepth skips recursion

`filterRowModelFromRoot` was discarding sub-rows when the parent
passed the filter but `depth >= maxLeafRowFilterDepth`. The parent
row got pushed into `flatRows` and `rowsById`, but the children
stayed reachable only via `row.subRows`, leaving `flatRows` an
incomplete view of the visible tree.

`column.getFacetedUniqueValues()` (which iterates `flatRows`)
returned consistent counts before filtering but inconsistent counts
after, because the pre-filter `flatRows` from the core row model
includes sub-rows while the filtered `flatRows` did not.

Add a small helper `addSubRowsToFlatArrays` that recursively pushes
each surviving sub-row into `flatRows` and `rowsById`, and call it
from the `else if` branch the parent-pass / depth-skipped case
falls into. The branch is reached only when `row.subRows.length`
is truthy, so the helper always has work to do.

Closes TanStack#6361 (refs TanStack#5987)
@coderabbitai

coderabbitai Bot commented Jul 9, 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

Run ID: 90310c85-ffa8-445f-aa15-823a25204ae5

📥 Commits

Reviewing files that changed from the base of the PR and between 9db621f and b6352cc.

📒 Files selected for processing (1)
  • packages/table-core/src/features/column-filtering/filterRowsUtils.ts

📝 Walkthrough

Walkthrough

Adds a recursive helper addSubRowsToFlatArrays in filterRowModelFromRoot that mirrors a passing row's sub-rows into flatRows and rowsById when recursion is halted by maxLeafRowFilterDepth, fixing inconsistency between row.subRows and the flattened row representation.

Changes

flatRows Consistency Fix

Layer / File(s) Summary
Add flatRows mirroring helper
packages/table-core/src/features/column-filtering/filterRowsUtils.ts
Adds addSubRowsToFlatArrays helper that recursively appends sub-rows into newFilteredFlatRows/newFilteredRowsById, and invokes it in the filtering recursion when a passing row's depth reaches maxDepth but still has subRows.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix for column filtering and flatRows behavior at maxLeafRowFilterDepth.
Linked Issues check ✅ Passed The change matches issue #6361 by adding skipped sub-rows to flatRows and rowsById when recursion stops at max depth.
Out of Scope Changes check ✅ Passed The diff stays focused on the filtering bug fix and does not introduce unrelated changes.
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.

1 participant