Skip to content

fix: fix extra span element when children is null#53723

Merged
afc163 merged 1 commit intomasterfrom
Checkbox-fix
May 6, 2025
Merged

fix: fix extra span element when children is null#53723
afc163 merged 1 commit intomasterfrom
Checkbox-fix

Conversation

@li-jia-nan
Copy link
Copy Markdown
Member

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English 修复 children === null 的时候渲染多余 dom
🇨🇳 Chinese 修复 children === null 的时候渲染多余 dom

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • 修复了复选框组件在 childrennull 时仍然渲染标签的问题,现在仅在 children 不为 undefined 且不为 null 时才显示标签。

Walkthrough

本次变更对 Checkbox 组件的渲染逻辑进行了调整。具体来说,组件现在只有在 children 属性既不是 undefined 也不是 null 时,才会渲染标签 <span>。此前的实现只排除了 undefined,此次修改进一步排除了 null 的情况,以避免在 children 明确为 null 时仍然渲染标签。

Changes

文件路径 变更摘要
components/checkbox/Checkbox.tsx 修改了渲染 <span> 标签的条件,增加了对 null 的检查。

Poem

🐇
复选框代码又细查,
children 不见也不怕。
null 与 undefined 区分明,
标签渲染更精准。
代码如诗,逻辑如画,
小兔子为你鼓个掌!


📜 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 7b23caa and 528a612.

📒 Files selected for processing (1)
  • components/checkbox/Checkbox.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: build
  • GitHub Check: build preview
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: build
  • GitHub Check: size
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
components/checkbox/Checkbox.tsx (1)

180-182: 修复了当 children 为 null 时渲染多余 DOM 的问题

这个修改正确地解决了当 children 属性为 null 时依然渲染空 <span> 元素的问题。通过增加对 null 值的检查,确保只有在 children 既不是 undefined 也不是 null 时才渲染标签。这是一个很好的防御性编程实践,避免了不必要的 DOM 渲染,提高了组件的性能和可维护性。

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2025

Preview is ready

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2025

👁 Visual Regression Report for PR #53723 Failed ❌

🎯 Target branch: master (7b23caa)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎
📊 Summary: 🛑 1 removed

Expected (Branch master) Actual (Current PR) Diff
select-basic.mobile.css-var.png select-basic.mobile.css-var.png ⛔️⛔️⛔️ Missing ⛔️⛔️⛔️ 🚨🚨🚨 Removed 🚨🚨🚨

Important

There are 1 diffs found in this PR: 🛑 1 removed.
Please check all items:

  • Visual diff is acceptable

@petercat-assistant
Copy link
Copy Markdown

Walkthrough

This pull request addresses a bug where an extra <span> element was rendered when the children prop was null. The fix ensures that the <span> is only rendered when children is not undefined and not null.

Changes

File Summary
components/checkbox/Checkbox.tsx Fixed the condition to prevent rendering an extra <span> when children is null.

Comment thread components/checkbox/Checkbox.tsx
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2025

size-limit report 📦

Path Size
dist/antd.min.js 448.98 KB (-1 B 🔽)
dist/antd-with-locales.min.js 535.08 KB (-1 B 🔽)

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 4, 2025

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2025

Bundle Report

Changes will decrease total bundle size by 6 bytes (-0.0%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.38MB -6 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js -3 bytes 1.84MB -0.0%
antd.min.js -3 bytes 1.54MB -0.0%

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying ant-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 528a612
Status: ✅  Deploy successful!
Preview URL: https://6c7bda1b.ant-design.pages.dev
Branch Preview URL: https://checkbox-fix.ant-design.pages.dev

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7b23caa) to head (528a612).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #53723   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          769       769           
  Lines        13907     13908    +1     
  Branches      3653      3654    +1     
=========================================
+ Hits         13907     13908    +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@huang-ze-jia huang-ze-jia left a comment

Choose a reason for hiding this comment

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

children != null 就可以了吧,包含了children !== undefined && children !== null的情况

@li-jia-nan
Copy link
Copy Markdown
Member Author

children != null 就可以了吧,包含了children !== undefined && children !== null的情况

!= 不够严格,用 !== 更遵循 antd 代码规范,另外也要和其它地方保持一致

@huang-ze-jia
Copy link
Copy Markdown

children != null 就可以了吧,包含了children !== undefined && children !== null的情况

!= 不够严格,用 !== 更遵循 antd 代码规范,另外也要和其它地方保持一致

ok

Copy link
Copy Markdown

@huang-ze-jia huang-ze-jia left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 6, 2025
@afc163 afc163 merged commit f64e575 into master May 6, 2025
52 checks passed
@afc163 afc163 deleted the Checkbox-fix branch May 6, 2025 02:21
@MadCcc MadCcc mentioned this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants