Skip to content

Conversation

yellowryan
Copy link
Contributor

@yellowryan yellowryan commented Feb 23, 2025

This pr related to ant-design#52816

Summary by CodeRabbit

  • 系统优化
    • 改进了通知配置的更新机制,提升了通知弹出、展示与关闭的响应速度和稳定性。
  • 测试增强
    • 新增了交互测试,确保在调整通知显示时长后,通知能按预期正确显示和消失。

Copy link

vercel bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
notification ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2025 8:36am

Copy link

coderabbitai bot commented Feb 23, 2025

Walkthrough

本次修改在 useNotification 钩子中引入了 shareConfig 的 memoization 处理,通过在解构后使用 React.useMemo 创建 memoized 配置对象,以便只有在特定属性(如 closeIconclosabledurationshowProgresspauseOnHover)变化时才重新计算。与此同时,相应地更新了 open 方法和其依赖,确保配置合并更加高效。此外,还在测试中新增了对使用 useState 修改通知持续时间的验证,确保组件行为符合预期。

Changes

文件 变更摘要
src/hooks/useNotification.tsx useNotification 中新增对 shareConfig 的 memoization,并在 open 方法中使用 memoized 配置,同时更新 api 的依赖数组
tests/index.test.tsx 新增测试用例,验证通过 useState 修改通知 duration 属性时,通知显示和隐藏行为正确

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant N as useNotification
    participant M as memoShareConfig
    U->>N: 调用 open() 方法传入自定义配置
    N->>M: 获取 memoized shareConfig(依赖更新时重新计算)
    N->>N: 合并 memoized shareConfig 与传入配置
    N-->>U: 展示通知(基于合并后的配置)
Loading

Possibly related PRs

Poem

我是跳跃的小兔子,在代码林中欢唱,
用 memo 织就配置梦,轻盈又稳当,
每条通知像晨曦,闪烁着希望的光,
状态变幻中见真章,测试验证步步长,
我在此刻轻轻跃,庆祝代码的美丽梦 🐰
前行在优化路上,辉煌未来共展望!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/hooks/useNotification.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

tests/index.test.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 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 f4c10c1 and 3c382f3.

📒 Files selected for processing (2)
  • src/hooks/useNotification.tsx (2 hunks)
  • tests/index.test.tsx (1 hunks)
🔇 Additional comments (3)
src/hooks/useNotification.tsx (2)

110-116: 优化实现:通过 memoization 提高性能!

通过对 shareConfig 中的关键属性(closeIconclosabledurationshowProgresspauseOnHover)进行 memoization 处理,可以避免不必要的重新渲染,提高了组件的性能。


122-122: 正确使用 memoized 配置!

api.open 方法中使用 memoShareConfig 并将其添加到 useMemo 的依赖数组中,确保了配置的一致性和正确的更新时机。

Also applies to: 137-137

tests/index.test.tsx (1)

853-894: 测试用例完善且全面!

新增的测试用例很好地验证了:

  1. 通过 useState 修改 duration 的功能
  2. 不同 duration 值对通知显示时间的影响
  3. 通知的自动消失时机

测试覆盖了关键场景,确保了全局 duration 功能的正确性。

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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 Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.74%. Comparing base (f4c10c1) to head (3c382f3).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #365   +/-   ##
=======================================
  Coverage   99.74%   99.74%           
=======================================
  Files           7        7           
  Lines         773      781    +8     
  Branches      125      126    +1     
=======================================
+ Hits          771      779    +8     
  Misses          2        2           

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

@afc163 afc163 merged commit d315300 into react-component:master Feb 24, 2025
9 checks passed
@yellowryan
Copy link
Contributor Author

antd 引入新版本rc-notification的pr还需要提么

@yoyo837
Copy link
Member

yoyo837 commented Feb 25, 2025

antd 引入新版本rc-notification的pr还需要提么

先发个patch再看需要。

Comment on lines +110 to +116
// memorized shareConfig
const { closeIcon, closable, duration, showProgress, pauseOnHover } = shareConfig;
const memoShareConfig = React.useMemo<typeof shareConfig>(() => {
return {
...shareConfig,
};
}, [closeIcon, closable, duration, showProgress, pauseOnHover]);
Copy link
Contributor

Choose a reason for hiding this comment

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

closable 类型可以是一个对象,感觉会破坏memo,这里修复方案我感觉可以直接用 rc-util 的 useEvent 就好了。 万金油。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这样啊,那有这个hook最好了,又探索到了😀

@Wxh16144 Wxh16144 mentioned this pull request Feb 25, 2025
Wxh16144 pushed a commit to Wxh16144-forks/notification that referenced this pull request Apr 16, 2025
…eact-component#365)

* fix: some properties changed by useState are not work

* test: add test

(cherry picked from commit d315300)
afc163 pushed a commit that referenced this pull request Apr 16, 2025
Co-authored-by: Ryan <[email protected]>
fix: global duration not work(Also includes some other attributes) (#365)
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.

4 participants