Skip to content

fix(table-core): point sorted row model rowsById at sorted branch clones - #6635

Open
koreahghg wants to merge 1 commit into
TanStack:mainfrom
koreahghg:feat-sorted-row-model-rows-by-id
Open

koreahghg wants to merge 1 commit into
TanStack:mainfrom
koreahghg:feat-sorted-row-model-rows-by-id

Conversation

@koreahghg

@koreahghg koreahghg commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

When sorting re-orders a parent's subRows, createSortedRowModel clones that parent, but rowsById was reused from the pre-sorted row model. As a result, table.getRow(id) returned the original parent with unsorted subRows, which is not the row rendered in getRowModel().rows.

rowsById is now copied the first time a branch row is cloned, and each clone is written into the copy. When no branch is cloned, the existing map is still reused. Two regression tests are added to createSortedRowModel.test.ts.

✅ 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.
  • This change is docs/CI/dev-only (no release).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed sorted hierarchical rows so retrieving a row by ID returns the correctly sorted row, including sorted child rows.
    • Preserved existing row references when sorting does not require cloning, improving consistency and stability.
  • Tests

    • Added coverage for row lookup behavior, row identity preservation, and sorted nested rows.

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

changeset-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9be42c6

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 Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/table/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e42ae8aa-2bc8-4f20-8f1d-88c07d5de5ce
📥 Commits

Reviewing files that changed from the base of the PR and between 95c4768 and 9be42c6.

📒 Files selected for processing: 3
  • .changeset/sorted-rows-by-id.md
  • packages/table-core/src/features/row-sorting/createSortedRowModel.ts
  • packages/table-core/tests/implementation/features/row-sorting/createSortedRowModel.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.

📝 Walkthrough

Nested sorting now updates rowsById to reference cloned rows. When sorting does not clone rows, the sorted model reuses the original lookup map.

Changes: Sorted row lookup

Layer / File(s) Summary
Update sorted row lookup
packages/table-core/src/features/row-sorting/createSortedRowModel.ts, packages/table-core/tests/implementation/features/row-sorting/createSortedRowModel.test.ts, .changeset/sorted-rows-by-id.md
When nested sorting clones rows, the sorted model copies rowsById and indexes the clones. Tests check lookup results, unchanged row identity, sorted child order, and reuse of the original map when there are no clones. The changeset documents the update.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: kevinvandy

Merge Risk: ⚪ Minimal · up to 9be42

The sorted-row lookup change has no identified merge-blocking issue in the supplied evidence; proceed with normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: updating table-core sorted row models so rowsById points to sorted branch clones.
Description check Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the problem, implementation, tests, and changeset, and all applicable checklist items are marked comp…
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.
Full details: Description check

Explanation

The description includes the required Changes, Checklist, and Release Impact sections. It explains the problem, implementation, tests, and changeset, and all applicable checklist items are marked complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ 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

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

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