Skip to content

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

Description

@MILLERMARRU

#6503 fixed maxLeafRowFilterDepth under filterRowModelFromRoot so a truncated subtree's descendants still land in flatRows/rowsById even though recursion stopped. The PR says this was deliberately scoped to that one path:

maxLeafRowFilterDepth keeps flatRows/rowsById complete. When the root-down recursion stops at the max depth, the kept rows' unfiltered descendants stay visible through row.subRows but never entered the flat arrays, under-counting facets after filtering. Truncated subtrees now join both. Scoped to the root-down path like the original PR; the leaf-up path drops truncated subRows entirely (pre-existing behavior) and is left as a possible follow-up.

Checked filterRowsUtils.ts on main: filterRowModelFromRoot now calls addSubRowsToFlatArrays(row.subRows, newFilteredFlatRows, newFilteredRowsById) when depth >= maxDepth, but filterRowModelFromLeafs's recurseFilterRows has no equivalent. Its recursion is newRow.subRows = recurseFilterRows(row.subRows, depth + 1), gated by if (row.subRows.length && depth < maxDepth), with no branch for depth >= maxDepth, so once the max depth is hit the subtree just isn't included in subRows, flatRows, or rowsById at all, not "still visible but not flattened," actually gone.

That's a different failure mode than the one #6503 fixed (silent under-count in flat-derived data like facets) since here the descendants disappear from row.subRows too, so they're not even rendered as nested rows in the tree, not just missing from the flat arrays.

Repro (with filterFromLeafRows: true):

const table = useReactTable({
  data, columns,
  getSubRows: row => row.subRows,
  getCoreRowModel: getCoreRowModel(),
  getFilteredRowModel: getFilteredRowModel(),
  filterFns: { fuzzy: fuzzyFilter },
  state: { columnFilters },
  filterFromLeafRows: true,
  maxLeafRowFilterDepth: 1,
})

// row 'a' has a matching child 'a1' at depth 1, and 'a1' has its own
// child 'a1x' at depth 2, beyond maxLeafRowFilterDepth

table.getFilteredRowModel().rowsById['a1']?.subRows
// expected (matches root-down behavior after #6503): still contains a1x
// actual: [] — a1x is gone from subRows, flatRows, and rowsById alike

Since #6503 already names this exact gap as a known follow-up, opening this mainly so there's something to reference from a PR rather than leaving the note buried in an unrelated changelog entry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions