useDateSegment crashes for locales whose 12-hour format has no dayPeriod part (e.g. fr-CM)
维护者通常 1 天内回复
@mangeshraut712 已经在做这个了。
开始于 2026年10月23日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript
调研方向
从 packages/react-aria/src/datepicker/useDateSegment.ts 中 issue 所述的 amPmFormatter 和 dayPeriod 查找处开始。检查 AM/PM 按键检查如何处理 day period 缺失的情况,以及它们是否会在仅包含日期的 segment 上运行。使用 locale fr-CM 复现;当 formatter 省略 dayPeriod 时,DateField、DatePicker 和 TimeField 均能正常渲染且不崩溃,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Provide a general summary of the issue here
DatePicker, DateField and TimeField throw during render when the locale is fr-CM. useDateSegment assumes a 12-hour formatter always outputs a dayPeriod part, but for some locales it doesn't.
🤔 Expected Behavior?
The field renders normally. A locale with no AM/PM marker should at worst make AM/PM typing unavailable, not crash, and a date-only field shouldn't need AM/PM at all.
😯 Current Behavior
TypeError: Cannot read properties of undefined (reading 'value')
at useDateSegment
packages/react-aria/src/datepicker/useDateSegment.ts (lines 151 and 157 on main):
let amPmFormatter = useDateFormatter({hour: 'numeric', hour12: true});
let am = useMemo(() => {
let date = new Date();
date.setHours(0);
return amPmFormatter.formatToParts(date).find(part => part.type === 'dayPeriod')!.value;
}, [amPmFormatter]);
For fr-CM, ICU returns no dayPeriod part (Node 20, ICU 76):
new Intl.DateTimeFormat('fr-CM', {hour: 'numeric', hour12: true}).formatToParts(new Date(2000, 0, 1, 0))
// [{type: 'hour', value: '0'}]
new Intl.DateTimeFormat('fr', {hour: 'numeric', hour12: true}).formatToParts(new Date(2000, 0, 1, 0))
// [{type: 'hour', value: '0'}, {type: 'literal', value: ' '}, {type: 'dayPeriod', value: 'AM'}]
These memos run for every segment, so a date-only field with no dayPeriod segment crashes too.
💁 Possible Solution
Guard the lookup:
return amPmFormatter.formatToParts(date).find(part => part.type === 'dayPeriod')?.value ?? '';
The startsWith(am, key) / startsWith(pm, key) checks would also need to skip an empty string. Otherwise every key would match, since every string starts with ''. Computing am/pm only when segment.type === 'dayPeriod' would also avoid the work for every other segment.
🔦 Context
Visitors whose browser locale is fr-CM couldn't open a birthdate picker; the field crashed on render. Because the default locale comes from navigator.language, apps hit this without configuring anything. We're working around it by wrapping DateInput in an I18nProvider that falls back from fr-CM to fr when the locale has no day period.
🖥️ Steps to Reproduce
import {I18nProvider} from 'react-aria';
import {DateField, DateInput, DateSegment, Label} from 'react-aria-components';
<I18nProvider locale="fr-CM">
<DateField>
<Label>Birthdate</Label>
<DateInput>{segment => <DateSegment segment={segment} />}</DateInput>
</DateField>
</I18nProvider>
Or set the browser language to fr-CM and render any DateField without an I18nProvider.
Version
react-aria 3.51.0 / react-aria-components 1.20.0; still present on main.
What browsers are you seeing the problem on?
All
What operating system are you using?
MacOS 26
🧢 Your Company/Team
Planning Center
🕷 Tracking Issue
- 主要语言
- TypeScript
- 星标
- 16k
- 派生
- 1.6k
- 平均合并
- 3 天 19 小时
- 30 天内合并 PR
- 46
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
adobe/react-spectrum 的其他 Issue
-
PreviewTrigger: the preview dialog has no accessible name可能已有人在做 @therealemmanueloppong 今天认领。 未关闭accessibility bug PreviewTrigger
难度 2/5 1-3 小时 新手友好度 76/100
adobe/react-spectrum#10917 · 3 条评论 ·
维护者通常 1 天内回复
-
S2 quiet Picker menu is always 192px wide: its width calc() has no unit可能已有人在做 @darshpatel1052 于 3 天前认领。 未关闭waiting on author
难度 2/5 1 小时以内 新手友好度 88/100
adobe/react-spectrum#10909 · 3 条评论 ·
维护者通常 1 天内回复
-
DatePicker omits timezone for initially empty fields despite zoned placeholderValue可能已有人在做 @mrlexcoder 于 3 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
adobe/react-spectrum#10900 · 2 条评论 ·
维护者通常 1 天内回复
-
Separator adds a redundant role="separator" to its default <hr>可能已有人在做 @Janani-bn 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
adobe/react-spectrum#10894 · 2 条评论 ·
维护者通常 1 天内回复
-
ComboBox with selectionMode="multiple": Cmd/Ctrl+A does nothing while the popover is open可能已有人在做 @mangeshraut712 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
adobe/react-spectrum#10866 ·
维护者通常 1 天内回复
查看 adobe/react-spectrum 的全部 Issue
相似的 Issue
-
Chip source filter and denial markers miss Storage rows when a Storage activity source is picked未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
omdsh-dev/DSH-better-sidebar#1141 ·
维护者通常 2 天内回复
-
desktop linux photos
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Cleanup Setup可能已有人在做 @AlexanderKaran 今天认领。 未关闭documentation enhancement
难度 2/5 1-3 小时 新手友好度 64/100
e18e/framework-tracker#769 ·
维护者通常 1 天内回复
-
bug v2
难度 1/5 1 小时以内 新手友好度 88/100
modelcontextprotocol/servers#5483 ·
维护者通常 1 天内回复