Skip to content
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

Merged
merged 6 commits into from
Feb 7, 2025

Conversation

Wxh16144
Copy link
Member

@Wxh16144 Wxh16144 commented Feb 7, 2025

Co-authored-by: SakuraHentai [email protected]

fix #189
close #190

Summary by CodeRabbit

  • 重构

    • 优化了样式清理逻辑,确保在组件卸载时能正确移除样式并依附到指定容器中。
  • 测试

    • 新增测试用例验证组件卸载时样式的自动清理,进一步提升样式管理的稳定性。

Copy link

coderabbitai bot commented Feb 7, 2025

📝 Walkthrough

Walkthrough

本次变更主要在两个样式钩子(useCSSVarRegister 与 useStyleRegister)中更新了 removeCSS 的调用,新增了 attachTo 参数以指定容器,从而确保在 shadowRoot 场景下能正确清理旧样式。此外,useCacheToken 中的清理逻辑从使用数组改为 Set,以优化 token 样式的清理判断逻辑。同时新增单元测试,验证组件卸载时样式能正确清除。

Changes

文件 变更摘要
src/hooks/useCSSVarRegister.ts 与 src/hooks/useStyleRegister.tsx 修改 removeCSS 调用,新增 attachTo: container 参数
src/hooks/useCacheToken.tsx 优化 token 清理逻辑,使用 Set 替代数组,并更新计数条件
tests/index.spec.tsx 增加测试用例,验证组件卸载时样式清理行为

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: 从指定容器移除样式
Loading

Assessment against linked issues

目标 是否解决 说明
传递 container 参数修复 shadowRoot 下主题切换失效([#189, #190])

Possibly related PRs

Poem

我是一只跳跃的兔子,
在代码草原自由驰骋,
attachTo 闪耀如同星辰,
样式清理整齐纯净,
逻辑优化欢歌笑语,
与你共庆这美好代码时光 🐰✨

✨ 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 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.87%. Comparing base (bed0452) to head (f9eff0d).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between bed0452 and f9eff0d.

📒 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: 测试用例设计合理!

新增的测试用例很好地验证了以下场景:

  1. 在自定义容器中正确插入样式
  2. 组件卸载时正确清理样式
  3. 同时测试了普通样式和 CSS 变量的清理

这确保了 PR 修复的问题不会再次出现。

@MadCcc MadCcc merged commit 35f041c into ant-design:master Feb 7, 2025
8 checks passed
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.

在shadowRoot中使用时, 切换theme算法无效.
3 participants