-
Notifications
You must be signed in to change notification settings - Fork 73
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: removeCSS
not work with container
#211
Conversation
📝 WalkthroughWalkthrough本次变更主要在两个样式钩子(useCSSVarRegister 与 useStyleRegister)中更新了 removeCSS 的调用,新增了 attachTo 参数以指定容器,从而确保在 shadowRoot 场景下能正确清理旧样式。此外,useCacheToken 中的清理逻辑从使用数组改为 Set,以优化 token 样式的清理判断逻辑。同时新增单元测试,验证组件卸载时样式能正确清除。 Changes
Sequence Diagram(s)sequenceDiagram
participant C as 组件
participant H as 样式钩子
participant R as removeCSS
participant D as DOM 容器
C->>H: 触发卸载或样式清理
H->>R: 调用 removeCSS(styleId, { mark, attachTo: container })
R->>D: 从指定容器移除样式
Assessment against linked issues
Possibly related PRs
Poem
✨ 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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #211 +/- ##
==========================================
- Coverage 94.88% 94.87% -0.01%
==========================================
Files 33 33
Lines 2892 2889 -3
Branches 456 456
==========================================
- Hits 2744 2741 -3
Misses 148 148 ☔ View full report in Codecov by Sentry. |
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/useCacheToken.tsx (1)
95-98
: 优化代码实现!使用 Set 替代数组来存储可清理的 token,提高了性能并使代码更简洁。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/hooks/useCSSVarRegister.ts
(1 hunks)src/hooks/useCacheToken.tsx
(1 hunks)src/hooks/useStyleRegister.tsx
(1 hunks)tests/index.spec.tsx
(2 hunks)
🔇 Additional comments (3)
src/hooks/useCSSVarRegister.ts (1)
61-61
: 代码变更正确!添加
attachTo: container
参数确保了 CSS 变量能够在指定容器中正确清理。src/hooks/useStyleRegister.tsx (1)
464-464
: 代码变更正确!添加
attachTo: container
参数确保了样式能够在指定容器中正确清理。tests/index.spec.tsx (1)
430-467
: 测试用例设计合理!新增的测试用例很好地验证了以下场景:
- 在自定义容器中正确插入样式
- 组件卸载时正确清理样式
- 同时测试了普通样式和 CSS 变量的清理
这确保了 PR 修复的问题不会再次出现。
Co-authored-by: SakuraHentai [email protected]
fix #189
close #190
Summary by CodeRabbit
重构
测试