Skip to content

fix(Table): useTableSortableState sorts an Invalid Date like null instead of throwing - #12921

Closed
josephfarina wants to merge 2 commits into
mainfrom
ca2-sort-invalid-date
Closed

josephfarina wants to merge 2 commits into
mainfrom
ca2-sort-invalid-date

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What changes for users

A Table that sorts with useTableSortableState crashed when a sorted column held an Invalid Date (for example new Date('not a date') from a bad API value). The default comparator calls toISOString(), which throws a RangeError for an Invalid Date. Now an Invalid Date sorts like a missing value: last in ascending order, first in descending order. Valid dates keep sorting by their time.

Root cause

defaultCompare treated only null, undefined and NaN as missing. Every other value went to toSortableString, and that called toISOString() on any Date, valid or not.

Fix

A new isMissingSortValue helper is the one place that decides which values are missing. It now also counts a Date whose getTime() is NaN. Missing values keep their existing order, so an Invalid Date goes where null and NaN already go. No current record decides where missing values sort. The existing tests and the doc's comparators text put null, undefined and NaN last in ascending order, so an Invalid Date follows them. A custom comparator still takes over completely for its key.

Spec and records

pnpm specs:for packages/core/src/Table/plugins/sortable/useTableSortableState.tsx routes to component:Table. No sortable module record exists, and no Table claim decides where missing values sort, so this fix creates no new policy. The doc line that lists the missing values (null, undefined and NaN) is also edited in the open docs PR #12884; it gains "an Invalid Date" in a follow-up after that lands, so the two PRs don't conflict.

Tests

  • useTableSortableState.test.tsx adds "Invalid Date handling": an Invalid Date sorts last in ascending order and first in descending order, next to the existing NaN and null cases. On main the comparator throws a RangeError for these rows.
  • astracat preflight: install, lint, build, typecheck and the test-ui gates passed. The node tests the change reaches (2,433 files) are left to the batched CI run. The touched ui test file was run on its own: the two new cases and the rest pass, except "re-sorts strings when the provider locale changes", which also fails at the merge base with that machine's Node.

Follow-ups (not in this PR)

  • Table's default cell renderer (columnUtils.ts) also calls toISOString() on any Date, so a column without renderCell still throws when it renders an Invalid Date. Fixing it means deciding what text an Invalid Date shows, so it is a separate change.
  • The hook doc's comparators text gains "an Invalid Date" after docs: useTableSortableState comparator rules; Table has no row-click prop #12884 lands (same line).

Changeset

[fix] for @astryxdesign/core (patch).

preflight: pass c1aaf66 (test-node left to the batch: 2,433 files)

@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 19, 2026 3:30pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 19, 2026
@astracat-bot

astracat-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 19, 2026, 3:34 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval waits on one decision. No current spec says which values count as missing in useTableSortableState's default comparator, or where they sort. Counting an Invalid Date as missing (last in ascending order, first in descending order) therefore needs an engineering owner to confirm it, or to point to the spec that already decides it. An engineering owner records that decision by commenting /approve-spec with this head's full commit SHA, and as an engineering owner the author may do so.

  • Not blocking, but worth knowing: the Table's default cell renderer (defaultCellRenderer in packages/core/src/Table/columnUtils.ts) still calls toISOString() on any Date. A sorted Table whose Date column has no renderCell still throws RangeError: Invalid time value on the same value. One shared Date-to-text helper for it and toSortableString would close that, here or in a follow-up.
Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claims
    • Changeset: the hook no longer throws when a sorted column holds an Invalid Date. Verified: the two new tests fail on the base with RangeError: Invalid time value and pass on this head.
    • Changeset: the default comparator treats an Invalid Date like null, undefined and NaN, last ascending and first descending. Verified: useTableSortableState.tsx:37-43 and :186-196, the descending flip at :234, and both new tests.
    • Description: a Table sorting with the hook crashed on an Invalid Date because the comparator called toISOString(). Verified on the base (toSortableString, line 39).
    • Description: valid dates keep sorting by their time. Verified: the earlier date sorts first in both new tests, and the collator path is unchanged.
    • Description: only null, undefined and NaN counted as missing before, and other values reached toSortableString. Verified in substance: two numbers take the numeric path first.
    • Description: isMissingSortValue is the one place that decides which values are missing. Verified: it is defined at :37-43 and used only at :186-187.
    • Description: missing values keep their existing order, and a custom comparator still takes over for its key. Verified: :188-196 and :228-231.
    • Description: no current spec decides where missing values sort, and no sortable module record exists. Verified: the Table component spec has no such clause.
    • Description: the existing tests and the hook doc put null, undefined and NaN last ascending. Verified: the NaN and null test suites, and the doc's comparators text.
    • Description: the open docs pull request #12884 edits the same doc line, and the Invalid Date sentence follows after it lands. Verified that #12884 is open and edits that line. The doc sentence is not in this pull request.
    • Description: the ascending test throws on the base. Verified, and the descending test throws there too.
    • Description: a patch changeset for @astryxdesign/core. Verified.
  • Files
    • .changeset/sortable-state-invalid-date.md: clear.
    • packages/core/src/Table/plugins/sortable/useTableSortableState.test.tsx: clear. Both new cases fail on the base and pass here.
    • packages/core/src/Table/plugins/sortable/useTableSortableState.tsx: the placement waits on the decision above. The rewritten comment at :181-185 has one non-blocking style suggestion. The hook doc and the default cell renderer in other files are consistent except for the two notes above.

Automated review (maintainer link)

@josephfarina
josephfarina marked this pull request as ready for review November 19, 2026 15:22
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec c1aaf66

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet.

The earlier hold is settled: an engineering owner approved, for this head, counting an Invalid Date as a missing value (last in ascending order, first in descending order). The two new tests fail on the base with RangeError: Invalid time value and pass on this head, and nothing blocks.

  • Not blocking, for the planned follow-up: the Table's default cell renderer (defaultCellRenderer in packages/core/src/Table/columnUtils.ts) still calls toISOString() on any Date, so a sorted Table whose Date column has no renderCell still throws on the same value.
Claims and files checked

Review mode: incremental; reason: none

  • Claims
    • Changeset: the hook no longer throws when a sorted column holds an Invalid Date. Verified: both new tests fail on the base with RangeError: Invalid time value and pass on this head.
    • Changeset: the default comparator treats an Invalid Date like null, undefined and NaN, last in ascending order and first in descending order. Verified: useTableSortableState.tsx:37-43 and :184-194, the descending flip at :232, and both new tests.
    • Changeset: a patch fix for @astryxdesign/core. Verified.
    • Description: a Table that sorts with the hook crashed on an Invalid Date because the comparator called toISOString(). Verified on the base (toSortableString) and by the failing tests there.
    • Description: valid dates keep sorting by their time. Verified: the earlier date sorts first in both new tests, and the collator path is unchanged.
    • Description: only null, undefined and NaN counted as missing before, and other values went to toSortableString. Verified in substance: two numbers take the numeric path first.
    • Description: isMissingSortValue is the one place that decides which values are missing. Verified: defined at :37-43 and used only at :184-185.
    • Description: missing values keep their existing order, and a custom comparator still takes over for its key. Verified: :186-194 and :226-229.
    • Description: no current spec decides where missing values sort, and no sortable module spec exists. Verified: the Table component spec has no such clause.
    • Description: the existing tests and the hook doc put null, undefined and NaN last in ascending order. Verified: the NaN and null test suites, and the hook doc's comparators text.
    • Description: the open docs pull request #12884 edits the same doc line, and the Invalid Date sentence follows after it lands. Verified that #12884 is open; the sentence is not in this pull request.
    • Description: the new tests throw on the base. Verified: both fail there with RangeError.
    • Description: the author's preflight passed its install, build, typecheck and UI test gates. A statement about the author's run, not the code; consistent with this review, where install, the Core and theme builds and the test file pass.
    • Description: the locale re-sort test fails at the merge base on the author's machine. Not reproduced: it passes on both the base and this head here.
    • Description follow-ups: the default cell renderer still throws on an Invalid Date, and the hook doc sentence comes later. Verified: columnUtils.ts:291-292 and useTableSortableState.doc.mjs:58 are unchanged.
  • Files
    • .changeset/sortable-state-invalid-date.md: clear.
    • packages/core/src/Table/plugins/sortable/useTableSortableState.test.tsx: clear. Both new cases fail on the base and pass here.
    • packages/core/src/Table/plugins/sortable/useTableSortableState.tsx: clear. The earlier comment suggestion is applied; consistent with the hook doc and the default cell renderer apart from the two follow-ups.

Automated review (maintainer link)

josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
@josephfarina

Copy link
Copy Markdown
Contributor Author

Owner decision (engineering owner, covering #12921 in this batch at its current head): a sorted Table column counts an invalid Date as a missing value. useTableSortableState sorts that row with the other missing values (null, undefined and NaN): last when ascending, first when descending, instead of throwing. No API change.

josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12921 fix(Table): useTableSortableState sorts an Invalid Date like null instead of throwing
  Author: @josephfarina
- #12911 perf(cli): read a project's lockfile only for an Astryx package it has not installed
  Author: @josephfarina
- #12388 fix(core): a theme radius of different corners reaches what a Card, a Dialog and a menu hand each corner to
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12945.

This branch was successfully deployed

1 active deployment
Preview — c1aaf667 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant