Repository navigation
fix: support falsy itemKey values such as 0 and empty string - #75
mokshupadhyay wants to merge 1 commit into
Conversation
|
@mokshupadhyay is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
ChangesitemKey 处理
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
|
Hi @yoyo837, a friendly ping: this is ready for review whenever you have time. Happy to adjust anything. Thanks! |
itemKeyis typedReact.Key | ((item) => React.Key), so0and''are valid property names, but the key lookup was(itemKey && item?.[itemKey]) ?? index. A falsyitemKeymade the whole expression0or'', which??does not replace, so the item key silently became0/''instead of the item's value.The lookup now checks
itemKey !== undefined && itemKey !== nullbefore reading the property, and still falls back to the index when the property is missing.Before / after, from the new test (tuple data with
itemKey={0}, keys read fromOverflowContext):['k-0', 'k-1'](test fails)['k-0', 'k-1']The same test covers
itemKey=""with{ '': 'e-0' }style data and asserts that no React key warning is logged.Tests:
npx rc-testpasses (7 suites, 38 tests) and the new test fails on the original source.eslint src/reports 0 errors (4 warnings, identical on the base branch);tsc --noEmitprints no errors.Summary by CodeRabbit
0等有效键不再被错误地替换为索引。