Skip to content

fix: prevent crash in createSortedRowModel for unknown sorting column ids#6373

Merged
KevinVandy merged 1 commit into
TanStack:betafrom
koreahghg:fix-sorted-row-model-unknown-column-id
Jul 3, 2026
Merged

fix: prevent crash in createSortedRowModel for unknown sorting column ids#6373
KevinVandy merged 1 commit into
TanStack:betafrom
koreahghg:fix-sorted-row-model-unknown-column-id

Conversation

@koreahghg

@koreahghg koreahghg commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

createSortedRowModel's sorting.filter(...) force-cast table.getColumn(sort.id) to Column_Internal even when the lookup returned undefined (e.g. a column removed/renamed while its sorting state still references the old id). That undefined was then passed straight into column_getCanSort, which dereferences column.columnDef.enableSorting and throws a TypeError, crashing getSortedRowModel().

This guards the lookup so an unknown sorting column id is simply treated as unsortable instead of crashing the whole row model.

Added packages/table-core/tests/unit/features/row-sorting/createSortedRowModel.test.ts covering:

  • getSortedRowModel() no longer throws when sorting references a nonexistent column id
  • the row order falls back to the pre-sorted order when only unknown columns are sorted
  • sorting still works correctly on the remaining valid sort entries when one entry is unknown

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

… ids

sorting.filter() force-cast table.getColumn(sort.id) to Column_Internal
even when it returned undefined (e.g. a column removed while its sort
state persisted), so column_getCanSort threw when dereferencing
column.columnDef. Guard the lookup and treat unknown columns as
unsortable instead of crashing.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The availableSorting filter in createSortedRowModel now checks whether a column exists before calling column_getCanSort, preventing errors when sort state references non-existent columns. A new unit test suite verifies fallback to original order and partial sorting behavior when sort entries reference unknown or mixed valid/invalid column ids.

Changes

Safe sort column handling

Layer / File(s) Summary
Guard missing column in sort filter
packages/table-core/src/features/row-sorting/createSortedRowModel.ts
availableSorting now retrieves the column via table.getColumn(sort.id), checks existence, and only calls column_getCanSort if the column exists, otherwise returns false.
Unit tests for unknown sort columns
packages/table-core/tests/unit/features/row-sorting/createSortedRowModel.test.ts
New test suite verifies no throw on unknown sort column ids, fallback to original row order when all sorts are unknown, and partial sorting when some sort entries are valid.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preventing crashes in createSortedRowModel when sorting references unknown column ids.
✨ 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.

@nx-cloud

nx-cloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 812a763

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 7m 47s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 46s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-03 12:09:47 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 3, 2026

Copy link
Copy Markdown
More templates

@tanstack/alpine-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/alpine-table@6373

@tanstack/angular-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table@6373

@tanstack/angular-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table-devtools@6373

@tanstack/lit-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/lit-table@6373

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/TanStack/table/@tanstack/match-sorter-utils@6373

@tanstack/preact-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table@6373

@tanstack/preact-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table-devtools@6373

@tanstack/react-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table@6373

@tanstack/react-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table-devtools@6373

@tanstack/solid-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table@6373

@tanstack/solid-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table-devtools@6373

@tanstack/svelte-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/svelte-table@6373

@tanstack/table-core

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-core@6373

@tanstack/table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-devtools@6373

@tanstack/vue-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table@6373

@tanstack/vue-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table-devtools@6373

commit: 812a763

@KevinVandy KevinVandy merged commit 87249f7 into TanStack:beta Jul 3, 2026
8 checks passed
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.

2 participants