-
Notifications
You must be signed in to change notification settings - Fork 115
fix again #366
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
fix again #366
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough此次更新在 Changes
Sequence Diagram(s)sequenceDiagram
participant C as 组件
participant H as useNotification 钩子
participant E as useEvent
C->>H: 调用 open(config)
H->>E: 使用 useEvent 合并 shareConfig 和 config
E-->>H: 返回合并后的 open 函数
H->>C: 返回 api 对象(包含新 open 方法)
Possibly related PRs
Poem
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
src/hooks/useNotification.tsxOops! 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:
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. ✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@yellowryan 来看看 |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/hooks/useNotification.tsx (1)
111-119
: 使用 useEvent 优化实现,建议小幅改进使用 useEvent 重构 open 方法是个很好的改进,它避免了不必要的 memoization 并保持了一致的行为。
建议:考虑将 uniqueKey 的生成逻辑抽取为一个单独的函数,以提高代码的可维护性。
+const generateUniqueKey = () => { + const key = `rc-notification-${uniqueKey}`; + uniqueKey += 1; + return key; +}; const open = useEvent<NotificationAPI['open']>((config) => { const mergedConfig = mergeConfig(shareConfig, config); if (mergedConfig.key === null || mergedConfig.key === undefined) { - mergedConfig.key = `rc-notification-${uniqueKey}`; - uniqueKey += 1; + mergedConfig.key = generateUniqueKey(); } setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/hooks/useNotification.tsx
(2 hunks)
🔇 Additional comments (2)
src/hooks/useNotification.tsx (2)
122-133
: 优化的 API 对象 memoization使用空依赖数组是正确的,因为:
- useEvent 已经确保了 open 函数的稳定性
- close 和 destroy 方法都是通过 setTaskQueue 实现,它们的引用也是稳定的
这样的实现既简洁又保持了正确的缓存行为。
6-6
:✅ Verification successful
验证 rc-util 依赖
请确保项目的 package.json 中已正确添加 rc-util 依赖。
🏁 Script executed:
#!/bin/bash # 检查 package.json 中的 rc-util 依赖 cat package.json | jq '.dependencies["rc-util"]'Length of output: 60
确认:rc-util 依赖已正确添加
我们已验证项目的 package.json 文件中包含
"rc-util": "^5.20.1"
,因此引入useEvent
没有问题。请继续保持此实现;无需调整依赖或相关引用。
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #366 +/- ##
==========================================
- Coverage 99.74% 99.74% -0.01%
==========================================
Files 7 7
Lines 781 777 -4
Branches 126 125 -1
==========================================
- Hits 779 775 -4
Misses 2 2 ☔ View full report in Codecov by Sentry. |
* revert solution * fix again (cherry picked from commit 3b1e34b)
reason: #365 (comment)
Summary by CodeRabbit