-
-
Notifications
You must be signed in to change notification settings - Fork 237
refactor: Trigger use hooks instead of #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
演练该 PR 将 变更
代码审查工作量评估🎯 3 (中等) | ⏱️ ~20 分钟 可能相关的 PR
建议审查者
诗歌
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (1)tests/ref.test.tsx (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (5)
✏️ Tip: You can disable this entire section by setting 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 |
Summary of ChangesHello @zombieJ, 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 refactors the internal implementation of the Trigger component to embrace a more modern, hook-based approach for handling resize observations. By migrating from a component-based 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
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #604 +/- ##
=======================================
Coverage 97.26% 97.26%
=======================================
Files 17 17
Lines 949 952 +3
Branches 274 268 -6
=======================================
+ Hits 923 926 +3
Misses 26 26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the Trigger component to use the useResizeObserver hook instead of the <ResizeObserver> component. This is a great improvement that makes the code cleaner and more aligned with modern React hook patterns. The changes also improve the component's robustness by using getDOM to handle different types of child components, which is well-supported by a new test case.
I've added one suggestion to improve the type safety in the setTargetRef function. Also, the pull request title seems to be incomplete.
| const setTargetRef = useEvent((node: HTMLElement) => { | ||
| if (isDOM(node) && targetEle !== node) { | ||
| setTargetEle(node); | ||
| externalForwardRef.current = node; | ||
| const domNode = getDOM(node) as HTMLElement; | ||
|
|
||
| if (isDOM(domNode) && targetEle !== domNode) { | ||
| setTargetEle(domNode); | ||
| externalForwardRef.current = domNode; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation for node is HTMLElement, but with the introduction of getDOM, it can now also be a React component instance (as demonstrated by the new test case). It's better to use a more general type like any to reflect this and avoid potential type issues.
Additionally, the type assertion as HTMLElement is not entirely safe, as getDOM(node) can return null or other node types. It's better to remove the cast and rely on the isDOM() type guard to ensure domNode is an HTMLElement before using it.
| const setTargetRef = useEvent((node: HTMLElement) => { | |
| if (isDOM(node) && targetEle !== node) { | |
| setTargetEle(node); | |
| externalForwardRef.current = node; | |
| const domNode = getDOM(node) as HTMLElement; | |
| if (isDOM(domNode) && targetEle !== domNode) { | |
| setTargetEle(domNode); | |
| externalForwardRef.current = domNode; | |
| } | |
| }); | |
| const setTargetRef = useEvent((node: any) => { | |
| const domNode = getDOM(node); | |
| if (isDOM(domNode) && targetEle !== domNode) { | |
| setTargetEle(domNode); | |
| externalForwardRef.current = domNode; | |
| } | |
| }); |
Summary by CodeRabbit
发布说明
改进
测试
✏️ Tip: You can customize this high-level summary in your review settings.