Uh oh!
There was an error while loading. Please reload this page.
fix: prevent crash in createSortedRowModel for unknown sorting column ids - #6373
Conversation
… 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.
📝 WalkthroughWalkthroughThe 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. ChangesSafe sort column handling
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
View your CI Pipeline Execution ↗ for commit 812a763
☁️ Nx Cloud last updated this comment at |
Uh oh!
There was an error while loading. Please reload this page.
🎯 Changes
createSortedRowModel'ssorting.filter(...)force-casttable.getColumn(sort.id)toColumn_Internaleven when the lookup returnedundefined(e.g. a column removed/renamed while itssortingstate still references the old id). Thatundefinedwas then passed straight intocolumn_getCanSort, which dereferencescolumn.columnDef.enableSortingand throws aTypeError, crashinggetSortedRowModel().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.tscovering:getSortedRowModel()no longer throws whensortingreferences a nonexistent column id✅ Checklist
pnpm test:pr.