fix: should generate standard id via useId#1003
Conversation
- Add getTreeNodeId function to generate unique tree node IDs - Use useId() hook to generate unique tree ID - Fix aria-activedescendant to use the same ID format as TreeNode - Pass treeId prop through MotionTreeNode to TreeNode
|
@aojunhao123 is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello @aojunhao123, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the accessibility of the tree component by ensuring a robust and consistent mechanism for identifying individual tree nodes. It introduces unique identifiers for tree instances and their nodes, which are then correctly utilized by ARIA attributes like Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Walkthrough在 NodeList 中引入 useId 生成局部 treeId,并新增 getTreeNodeId 工具以生成复合节点 id;将 treeId 通过 props 传入 TreeNode/MotionTreeNode 并将 aria-activedescendant 改为引用复合 id;相应测试改为通过该 id 验证目标元素 role。 Changes
Sequence Diagram(s)(此变更为较小的可访问性/ID 生成调整,控制流无复杂多组件序列,故省略序列图。) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
诗歌
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an accessibility issue where aria-activedescendant did not match the TreeNode's id. By introducing a treeId using the useId hook and a getTreeNodeId helper function, it ensures unique and matching IDs are generated for the tree and its nodes. The implementation is sound and improves accessibility.
I have one major point of feedback regarding a circular dependency introduced by the placement of the new helper function. Please see my detailed comment on how to resolve this to prevent potential runtime issues.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/TreeNode.tsx`:
- Line 7: TreeNode.tsx 引入的 getTreeNodeId 导致循环依赖(TreeNode → NodeList →
MotionTreeNode → TreeNode);将 getTreeNodeId 从 NodeList.tsx 提取到新的工具模块(例如
utils/treeUtil.ts),并在 NodeList.tsx、TreeNode.tsx 中改为从该工具模块导入。确保导出的函数名保持
getTreeNodeId,更新所有对 getTreeNodeId 的导入路径,并运行构建/测试以验证循环依赖已消失。
🧹 Nitpick comments (1)
src/TreeNode.tsx (1)
409-410: 考虑treeId未定义的边界情况当
TreeNode在NodeList外部独立使用时,treeId可能为undefined,导致生成的nodeId为"undefined-${eventKey}",这不是有效的 ID 格式。建议添加防御性处理:
♻️ 建议修改
- const nodeId = getTreeNodeId(treeId, eventKey); + const nodeId = treeId ? getTreeNodeId(treeId, eventKey) : undefined;
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1003 +/- ##
=======================================
Coverage 99.84% 99.84%
=======================================
Files 14 14
Lines 1291 1295 +4
Branches 396 396
=======================================
+ Hits 1289 1293 +4
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| ...domProps | ||
| } = props; | ||
|
|
||
| const treeId = useId(); |
There was a problem hiding this comment.
useId在虚拟滚动情况下生成结果不稳定。直接在外层生成一个稳定 id 跟 key 拼接一下
Summary by CodeRabbit
发布说明
新功能
重构
测试
✏️ Tip: You can customize this high-level summary in your review settings.