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

chore: update stylis to avoid leading '&' generate invalid css #201

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

magicdawn
Copy link
Contributor

@magicdawn magicdawn commented Oct 27, 2024

升级 stylis 修复 bad css 如

:where(.css-ni1kz0)&.ant-btn-variant-outlined,
:where(.css-ni1kz0)&.ant-btn-variant-dashed {
  border-color: #d9d9d9;
  background: #ffffff;
}

stylis@v4.3.4 normalize 可以去除 :where(.css-ni1kz0)&.ant-btn-variant-outlined 中的 &

cssinjs

demo

https://codesandbox.io/p/sandbox/8vn48p?file=%2Fmain.js%3A11%2C2

在 external react / react-dom / dayjs / @ant-design/cssinjs / antd 后, <antd.Button></antd.Button> 没有边框, 是因为 border-color css 不生效, 可以看动图

cssinjs-demo

@ant-design/cssinjs/1.21.1/files/dist/umd/cssinjs.min.js 刚好是 stylis 4.3.3 打包的
https://unpkg.com/browse/@ant-design/cssinjs@1.21.1/package.json

Summary by CodeRabbit

  • 新功能

    • 更新了 stylis 依赖的版本,提升了样式处理的稳定性和性能。
  • 测试

    • 新增了 normalizeStyle 函数的测试套件,确保样式处理的准确性。

Copy link

coderabbitai bot commented Oct 27, 2024

📝 Walkthrough

Walkthrough

本次更改主要涉及 package.json 文件中的 @ant-design/cssinjs 包,更新了 stylis 依赖的版本,从 ^4.3.3 升级至 ^4.3.4。此外,在 tests/util.spec.tsx 文件中引入了一个新的测试套件,用于验证 normalizeStyle 函数的行为,特别是处理包含前导字符 & 的样式时的输出。

Changes

文件路径 更改摘要
package.json 更新 stylis 依赖版本:^4.3.3^4.3.4
tests/util.spec.tsx 新增测试套件 normalizeStyle 和测试用例 with leading &

Possibly related PRs

  • fix: root selector with single & #193: 此 PR 涉及 package.jsonstylis 版本的更新,与主 PR 中 stylis 依赖的版本提升直接相关。此外,它还修改了 CSS 选择器的处理,可能与主 PR 中 normalizeStyle 的新测试套件功能相关。

Poem

在草地上跳跃的小兔,
更新依赖,真是不错!
测试新样式,确保无误,
让代码更稳,像春天的花朵。 🌷
版本提升,欢声笑语,
兔子们一起庆祝这美好时刻! 🐇


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 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

@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

🧹 Outside diff range and nitpick comments (1)
tests/util.spec.tsx (1)

149-168: 测试用例完整验证了样式规范化功能

测试用例很好地覆盖了以下关键点:

  • 验证了 parseStyle 保留前导 & 的行为
  • 验证了 normalizeStyle 正确移除前导 & 的功能
  • 使用了实际场景中的选择器模式进行测试

建议添加以下测试场景以提高覆盖率:

  • 嵌套选择器中的前导 & 处理
  • 多层嵌套中的 & 处理
  • 伪类选择器中的 & 处理

示例补充测试用例:

it('should handle nested selectors with leading &', () => {
  const [str] = parseStyle({
    '.parent': {
      '&.child': {
        '&:hover': {
          color: 'red'
        }
      }
    }
  }, { hashId: 'hashed' });
  
  const normalized = normalizeStyle(str);
  expect(normalized).toContain('.hashed.parent.child:hover');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between be4e05b and 54607f6.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • tests/util.spec.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (2)
tests/util.spec.tsx (2)

151-158: 测试数据结构清晰且符合实际场景

测试用例中使用的选择器模式 &.btn-variant-outline,&.btn-variant-dashed 与 PR 中描述的实际问题相符,这有助于确保修复的有效性。


161-166: 断言验证了完整的转换流程

测试用例通过两个断言完整验证了样式处理流程:

  1. 首先验证 parseStyle 的输出包含前导 &
  2. 然后验证 normalizeStyle 正确移除了前导 &

这种分步验证的方式有助于快速定位潜在问题。

@magicdawn
Copy link
Contributor Author

same as #200

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.07%. Comparing base (880ed09) to head (54607f6).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #201   +/-   ##
=======================================
  Coverage   95.07%   95.07%           
=======================================
  Files          33       33           
  Lines        2883     2883           
  Branches      456      456           
=======================================
  Hits         2741     2741           
  Misses        142      142           

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

@afc163 afc163 merged commit eabc24e into ant-design:master Oct 27, 2024
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.

2 participants