Skip to content

fix: no warning #561

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

Merged
merged 1 commit into from
Jul 28, 2025
Merged

fix: no warning #561

merged 1 commit into from
Jul 28, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Jul 28, 2025

#528 中,剥离了 isMobile 检测降低 bundle size,使用更通用的方式进行自动切换。这使得在 hoverToClose 中也会添加一个 touchToClose 逻辑,从而走 shadowRoot 的检测。

在 React 18 中,setState 后会立刻触发 useEffect。而在 19 则会合并触发。这使得 targetElement 在 React 18 中会有一个额外的 useEffect warning 检测,导致 warning。然后在下一个 effect update 便跟上 targetElement,是一个无效 warning。

Summary by CodeRabbit

  • Bug Fixes
    • 修复了在获取目标元素根节点时的判断条件,避免因未定义的目标元素导致的潜在错误。

Copy link

coderabbitai bot commented Jul 28, 2025

Walkthrough

本次更改调整了 src/hooks/useWinClick.ts 中获取目标元素根节点的条件判断逻辑。现在仅在 targetEle 存在时才尝试调用其 getRootNode 方法,避免了对未定义元素的多余可选链调用,其他逻辑未变。

Changes

Cohort / File(s) Change Summary
目标元素根节点判断优化
src/hooks/useWinClick.ts
修改了获取目标元素根节点时的条件判断,仅在 targetEle 存在时调用 getRootNode,提升了代码健壮性,未影响其他逻辑。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 分钟

Poem

小兔子跳进代码林,
判断优化细又精。
只在元素真存在,
getRootNode 才运行。
逻辑如丝顺又明,
代码安全更安心! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53640ae and 3b077ac.

📒 Files selected for processing (1)
  • src/hooks/useWinClick.ts (1 hunks)
🔇 Additional comments (1)
src/hooks/useWinClick.ts (1)

56-57: 优化了目标元素存在性检查逻辑!

这个修改很好地解决了React 18中的警告问题:

  1. 明确性检查:通过显式检查 targetEle 的存在性,避免了在元素不存在时进行不必要的 getRootNode 调用
  2. 性能优化:减少了可选链调用的开销,只在确实需要时才执行shadow root检查
  3. 修复React 18警告:正如PR目标所述,这个改动应该能够防止React 18中由于 useEffect 立即触发导致的额外警告

代码逻辑更加清晰和高效。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-warning

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.75%. Comparing base (53640ae) to head (3b077ac).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #561   +/-   ##
=======================================
  Coverage   97.75%   97.75%           
=======================================
  Files          12       12           
  Lines         801      801           
  Branches      235      243    +8     
=======================================
  Hits          783      783           
  Misses         18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -53,8 +53,8 @@ export default function useWinClick(
}

// Warning if target and popup not in same root
if (process.env.NODE_ENV !== 'production') {
const targetRoot = targetEle?.getRootNode?.();
if (process.env.NODE_ENV !== 'production' && targetEle) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会不会导致这部分代码不会从 production 环境移除,从而使体积变大?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uglify 会短路,中间有 falsy 就会删掉。

@zombieJ zombieJ merged commit 665bca2 into master Jul 28, 2025
10 checks passed
@zombieJ zombieJ deleted the fix-warning branch July 28, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants