Skip to content

fix(table-core): ignore unselectable subtrees in sub-row selection state - #6666

Open
h00ns wants to merge 1 commit into
TanStack:mainfrom
h00ns:feat-fix-sub-row-selection-unselectable-subtrees
Open

h00ns wants to merge 1 commit into
TanStack:mainfrom
h00ns:feat-fix-sub-row-selection-unselectable-subtrees

Conversation

@h00ns

@h00ns h00ns commented Nov 20, 2026 •

Copy link
Copy Markdown

🎯 Changes

When a sub-row's descendants are all unselectable, the parent row treats that sub-row as "not all selected". So after selecting every row that can be selected, the parent still reports a partial selection, and its checkbox renders as indeterminate.

// P -> C -> [G1, G2], grandchildren are not selectable
const table = constructTable({
  // ...
  getSubRows: (r) => r.subRows,
  enableRowSelection: (row) => row.depth < 2,
})
const p = table.getCoreRowModel().rows[0]
p.toggleSelected(true) // { '0': true, '0.0': true }

p.getIsSomeSelected()       // expected false, actual true
p.getIsAllSubRowsSelected() // expected true,  actual false

Cause: isSubRowSelected returns false in two different cases: a subtree that has selectable rows but none are selected, and a subtree that has no selectable rows at all. Since #6491, a parent counts both as "not all selected". This affects table-core 9.0.0 through 9.3.1; v8 handled the second case correctly.

Fix: the recursion now goes through a private helper that returns undefined when a subtree has no selectable rows, and the parent skips those subtrees. isSubRowSelected keeps its signature and return values.

Updated test: should return some if no children are selectable, but a grand-child is and is selected expected 'some'. In that setup the only selectable descendant is selected; the result was 'some' only because a sibling subtree with no selectable rows was counted as unselected. That contradicts the JSDoc ("all selectable descendants are selected") and the existing test should return all if all selectable sub-rows are selected, so it now expects 'all' and is renamed accordingly.

Added one implementation test and one unit test for the row methods; all three fail without the fix.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm test and pnpm test:e2e, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected nested row-selection state reporting: rows are now considered fully selected when all selectable descendants are selected, even if other subtrees have no selectable rows.

`isSubRowSelected` returns `false` both when a row's selectable
descendants are all unselected and when it has no selectable
descendants at all. A parent treated both the same way, so a sub-row
whose children are all unselectable marked the parent as "not all
selected", even when every selectable descendant was selected.

Track the "no selectable descendants" case separately in the recursion
and skip those subtrees, so `row.getIsAllSubRowsSelected()` and
`row.getIsSomeSelected()` only look at rows that can be selected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 052ba98

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/table-core Patch
@tanstack/alpine-table Patch
@tanstack/angular-table-devtools Patch
@tanstack/angular-table Patch
@tanstack/ember-table Patch
@tanstack/lit-table Patch
@tanstack/octane-table Patch
@tanstack/preact-table Patch
@tanstack/react-table Patch
@tanstack/solid-table Patch
@tanstack/svelte-table Patch
@tanstack/vue-table Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Nested row-selection aggregation now ignores subtrees with no selectable descendants. Tests verify that a parent reports all selectable sub-rows selected when those rows are selected, even if deeper rows are not selectable.

Changes: Sub-row selection aggregation

Layer / File(s) Summary
Selection aggregation and validation
packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts, packages/table-core/tests/implementation/features/row-selection/rowSelectionFeature.test.ts, packages/table-core/tests/unit/features/row-selection/rowSelectionFeature.utils.test.ts, .changeset/sub-row-selection-unselectable-subtrees.md
Recursive selection checks distinguish unselected selectable descendants from subtrees with no selectable descendants. Tests expect 'all' when all selectable descendants are selected, and the changeset records the patch.

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

Change: Bug fix

Suggested reviewers: kevinvandy, willswebsites

Merge Risk: Minimal · up to 052ba

This fixes parent rows wrongly reporting partial selection when some sub-rows have no selectable descendants. The public API is unchanged, and tests cover the new behavior. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: sub-row selection state now ignores subtrees with no selectable rows. It also gives the fix type and the package (table-core). The title fits the changeset, the utils …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template. It explains the bug (a subtree with no selectable rows is counted as "not all selected"), gives a reproduction snippet with expected and actual values,…
Full details: Title check

Explanation

The title names the main change: sub-row selection state now ignores subtrees with no selectable rows. It also gives the fix type and the package (table-core). The title fits the changeset, the utils change, and the test updates.

Full details: Description check

Explanation

The description follows the repository template. It explains the bug (a subtree with no selectable rows is counted as "not all selected"), gives a reproduction snippet with expected and actual values, and states the cause and the fix. It also explains the updated test and the added tests. The checklist is completed, and the author marks the changeset as generated. The description does not give a changeset file name, but the raw summary shows one exists, so this is not a gap.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1cfb2e5 and 052ba98.

Files selected for processing: 4

  • .changeset/sub-row-selection-unselectable-subtrees.md
  • packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts
  • packages/table-core/tests/implementation/features/row-selection/rowSelectionFeature.test.ts
  • packages/table-core/tests/unit/features/row-selection/rowSelectionFeature.utils.test.ts

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

This branch has not been deployed

No deployments
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