fix(demo): format month via PlainDate to avoid calendar-mismatch crash#27
Merged
Conversation
The /demo page's onMonthChange handler called `toLocaleString` directly on
a `Temporal.PlainYearMonth`, which carries the iso8601 calendar. For locales
that resolve to a different calendar (e.g. gregory for en-US), Temporal throws
"cannot format PlainYearMonth with calendar iso8601 in locale with calendar
gregory" — so clicking the next/prev month button errored out.
Format through an ISO `PlainDate` (`.toPlainDate({ day: 1 })`) instead, which
Intl renders in the locale's calendar without throwing. This mirrors the
technique the library's own MonthYearString component already uses.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
✅ Deploy Preview for colander-cal ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
🎉 This PR is included in version 3.0.1-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
/demopage'sonMonthChangehandler formatted the month by callingtoLocaleStringdirectly on aTemporal.PlainYearMonth. Clicking the next/prev month button crashed with:This fixes it by formatting through an ISO
PlainDateinstead.Why
A
PlainYearMonth(andPlainMonthDay) carries theiso8601calendar. WhentoLocaleStringresolves a locale whose calendar differs (e.g.gregoryforen-US), Temporal throws on the calendar mismatch. An ISOPlainDatedoes not have this restriction —Intlrenders it in the locale's calendar — so converting via.toPlainDate({ day: 1 })before formatting avoids the crash.This mirrors the exact technique the library's own
MonthYearStringcomponent already uses (seepackage/src/navigation.tsx).Verification
Reproduced against
@js-temporal/polyfilldirectly (the source of the error):PlainYearMonthdirectly throws the exact error above..toPlainDate({ day: 1 }).toLocaleString(...)renders"July 2026".th-TH) correctly renders the Buddhist year2569, confirming locale calendars still display properly.Notes for reviewer
vp fmt/lintcouldn't be run in this worktree (its dependency tree isn't fully installed —vite-plus/@tanstack/devtools-vitemissing), so verification was done against the polyfill where the error originates. The edit follows the surrounding 2-space style and line-length conventions.PlainYearMonthdirectly (the one otherIntl.formatcall uses a nativeDate, which is safe).🤖 Generated with Claude Code