Repository navigation
fix: stop CalendarYearPicker from looping at year 9999 - #10841
Open
mangeshraut712 wants to merge 2 commits into
Open
mangeshraut712 wants to merge 2 commits into
mangeshraut712 wants to merge 2 commits into
Conversation
Date arithmetic clamps at the calendar maximum, so stepping forward from year 9999 repeats that year and never returns. Stop once the next step stays in the year just added, and keep that year inside maxValue.
6 of 7 tasks
A centered window shrinks at the minimum and maximum year. Slide the free end so visibleYears entries remain, and cover those boundaries in other calendars and locales.
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.
Closes #10839
useCalendarYearPickerwalks years withdate.add({years: 1})and keeps going while the date is still inside the range, or still in the maximum year, so aminValue/maxValuepair that ends mid-year still includes that last year. Gregorian dates cannot move past 9999:new CalendarDate(9999, 12, 31).add({years: 1})stays9999-12-31. The condition never becomes false, the year list grows without bound, and renderingCalendarYearPickerfocused on December 9999 locks the page. Clamping can also land a later day in 9999, which would list that year twice.After a year is added, stop when the next step is still that same year. The final supported year is included once. When
maxValuecuts that year short, the option date stays onmaxValue, same as the fix for the mid-year range in #10531. With no explicit maximum, a focused date of 9999-12-01 shows 9989–9999 (the centered window cannot extend past the calendar maximum, and nothing shifts it). An explicitmaxValueof 9999-06-01 still anchors a full 20-year list that ends on that date.✅ Pull Request Checklist:
No storybook or docs change: the public API and the year control are the same, and the list is just finite. Accessibility behavior of the picker is unchanged.
AI assistance: an assistant, pointed at AGENTS.md, reproduced the hang, added the regression test, and made this change.
📝 Test Instructions:
CalendarwithdefaultFocusedValue={new CalendarDate(9999, 12, 1)}and aCalendarYearPicker(the snippet in CalendarYearPicker enters an infinite loop at Gregorian year 9999 #10839).maxValue={new CalendarDate(9999, 6, 1)}and focus in December 9999, the list is 9980–9999 and the last option is 9999-06-01.minValue9998-08-03,maxValue9999-02-03, and focus in February 9999, the options are 9998 and 9999, and 9999 is backed by 9999-02-03.Before the fix, the new test never returned and the Jest process ran out of memory. The loop is synchronous, so the test timeout does not interrupt it.
After the fix:
yarn test packages/react-aria-components/test/Calendar.test.js packages/react-aria-components/test/RangeCalendar.test.tsx— 63 passedyarn lint— format check,yarn check-types, oxlint, package lint, and constraints passedNo separate mouse, keyboard, screen reader, RTL, or forced-colors pass: this only changes how many year options are built.
🧢 Your Project:
Personal contribution.
Please tell me if you would rather shift the default window so a full
visibleYearslist still ends on 9999.