Skip to content
Source
Sign inSign up
TanStack/table

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

Openkoreahghg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/6635/headopened

🎯 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.
    1. 🦋 Changeset detected

      Latest commit: 9be42c648d4dab885433e843bd1a1f99dc1a33bb

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

      This PR includes changesets to release 12 packages
      NameType
      @tanstack/table-corePatch
      @tanstack/alpine-tablePatch
      @tanstack/angular-table-devtoolsPatch
      @tanstack/angular-tablePatch
      @tanstack/ember-tablePatch
      @tanstack/lit-tablePatch
      @tanstack/octane-tablePatch
      @tanstack/preact-tablePatch
      @tanstack/react-tablePatch
      @tanstack/solid-tablePatch
      @tanstack/svelte-tablePatch
      @tanstack/vue-tablePatch

      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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 95c4768496c07b45b1e65d8e33c3291ac66eae9b and 9be42c648d4dab885433e843bd1a1f99dc1a33bb.

      📒 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 nameStatusExplanationResolution
      Docstring CoverageWarningDocstring 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 nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary change: updating table-core sorted row models so rowsById points to sorted branch clones.
      Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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.

Sign in to join this conversation.