Skip to content

Conversation

@li-jia-nan
Copy link
Member

@li-jia-nan li-jia-nan commented Jan 12, 2026

image

Summary by CodeRabbit

发布说明

  • Bug Fixes

    • 修复样式处理对 undefined/null 值的处理,避免无效样式被输出或应用。
  • New Features

    • 新增对外类型导出,提升类型可见性与集成友好性。
  • Tests

    • 添加边界情况测试以覆盖对空值样式的跳过行为。

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 12, 2026 19:03
@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2026

📝 Walkthrough

Walkthrough

导出并使用新工具函数 isNonNullable,在样式注册 Hook 中避免将 null/undefined 值追加为样式;新增若干公共类型导出,更新 .gitignore,并增加测试覆盖以验证跳过 padding: undefined 的行为。

Changes

Cohort / File(s) 变更摘要
配置文件
​.gitignore
添加 pnpm-lock.yaml 到忽略列表;修复文件末尾换行
样式注册 Hook
src/hooks/useStyleRegister.tsx
导入并使用 isNonNullable;在解析非 multi-value 的样式值时仅在值非 null/undefined 时调用 appendStyle,防止将空值写入样式
工具函数
src/util/index.ts
新增并导出类型保护函数 export const isNonNullable<T>(val: T): val is NonNullable<T>
公开类型导出
src/index.ts
新增类型导出:TokenType, CSSObject, CSSInterpolation, DerivativeFunc, Transformer, Linter, StyleProviderProps, AbstractCalculator(仅类型声明,未改动运行时逻辑)
测试
tests/index.spec.tsx
新增测试用例 “should skip appendStyle when value is null or undefined”,验证注册样式时 padding: undefined 不会被序列化/写入样式标签

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 我从草丛跳出,轻嗅一行新码,
无值不占位,样式更清雅,
类型伸出爪,测试稳如瓜,
小兔鼓掌笑,变更静又雅。

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题精准地描述了主要变更:跳过null或undefined值的appendStyle调用,与代码改动完全相符。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch padding-convert

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

🎊 PR Preview e9b67dd has been successfully built and deployed to https://ant-design-cssinjs-preview-pr-242.surge.sh

🕐 Build time: 102.432s

🤖 By surge-preview

@gemini-code-assist
Copy link

Summary of Changes

Hello @li-jia-nan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where undefined or null values for CSS padding properties were not handled gracefully during style generation. The changes ensure that such values are automatically converted to 0, providing more robust and predictable styling behavior. This improves the reliability of style application, particularly for dynamic styling scenarios, and includes a new utility function and corresponding test coverage.

Highlights

  • Padding Value Handling: Implemented a fix to convert undefined or null values for the padding CSS property to 0 when processing styles within useStyleRegister.
  • New Utility Function: Introduced a new utility function isNullable in src/util/index.ts to consistently check for null or undefined values.
  • Test Coverage: Added a new test case to tests/index.spec.tsx specifically verifying that undefined padding values are correctly converted to 0 in the generated CSS.
  • Git Ignore Update: Updated .gitignore to include pnpm-lock.yaml and ensure proper newline handling for bun.lockb.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.63%. Comparing base (c7c8631) to head (e9b67dd).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #242      +/-   ##
==========================================
+ Coverage   94.62%   94.63%   +0.01%     
==========================================
  Files          32       32              
  Lines        2810     2817       +7     
  Branches      443      446       +3     
==========================================
+ Hits         2659     2666       +7     
  Misses        151      151              

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to fix an issue where an undefined value for a style property is not handled correctly, by converting it to 0. The implementation focuses on the padding property. My review points out that the current fix is too specific and will not work for related properties like paddingTop. I've suggested a more robust solution to cover all padding-related properties and recommended updating the tests accordingly. Other changes include adding pnpm-lock.yaml to .gitignore and a new isNullable utility function, which look good.

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

🧹 Nitpick comments (1)
tests/index.spec.tsx (1)

952-982: 测试覆盖范围有限

测试用例验证了 padding: undefined 转换为 padding:0 的行为,但当前实现(useStyleRegister.tsx 第 327 行)使用 key.toLowerCase() === 'padding' 进行精确匹配,这意味着 paddingToppaddingLeftpaddingRightpaddingBottom 等属性的 undefined 值不会被转换。

建议确认这是预期行为,或者考虑扩展覆盖范围。

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7c8631 and 168e6ec.

📒 Files selected for processing (5)
  • .gitignore
  • src/hooks/useStyleRegister.tsx
  • src/index.ts
  • src/util/index.ts
  • tests/index.spec.tsx
🧰 Additional context used
🧬 Code graph analysis (2)
tests/index.spec.tsx (2)
src/hooks/useStyleRegister.tsx (2)
  • CSSInterpolation (67-70)
  • useStyleRegister (376-521)
src/hooks/useCacheToken.tsx (1)
  • useCacheToken (152-237)
src/hooks/useStyleRegister.tsx (1)
src/util/index.ts (1)
  • isNullable (204-206)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Agent
  • GitHub Check: preview
🔇 Additional comments (4)
.gitignore (1)

32-32: LGTM!

添加 pnpm-lock.yaml 到忽略列表是合理的,与现有的 yarn.lockpackage-lock.json 保持一致。

Also applies to: 47-47

src/index.ts (1)

54-64: LGTM!

新增的类型导出块使库的公共 API 更加完整,所有导出的类型都已在文件顶部正确导入。

src/util/index.ts (1)

203-206: LGTM!

isNullable 工具函数实现正确,类型守卫 val is Extract<T, null | undefined> 提供了良好的类型推断支持。

src/hooks/useStyleRegister.tsx (1)

18-18: LGTM!

正确导入了 isNullable 工具函数。

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses an issue where undefined CSS property values would be output as literal "undefined" strings in the generated CSS. The fix specifically converts undefined values to 0 for the padding property.

Changes:

  • Added a new isNullable utility function to check for null/undefined values
  • Modified style register hook to convert undefined padding values to 0
  • Added a test case validating the padding undefined-to-0 conversion
  • Updated .gitignore to include pnpm-lock.yaml

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/util/index.ts Adds isNullable utility function to check for null/undefined values
src/hooks/useStyleRegister.tsx Implements special handling to convert undefined padding values to 0
tests/index.spec.tsx Adds test case verifying undefined padding values are converted to 0
.gitignore Adds pnpm-lock.yaml to ignored files
src/index.ts Minor formatting change (blank line)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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/useStyleRegister.tsx (1)

326-331: 逻辑正确,但修复范围可能需要扩展。

当前实现仅对 padding 相关属性进行了 undefined/null0 的转换。这个修复本身是正确的,但存在以下疑问:

  1. 一致性问题:为什么只处理 paddingmarginborder-width 等属性是否也存在类似问题?如果其他属性也需要类似处理,建议统一处理或至少在注释中说明只处理 padding 的原因。

  2. 边界情况key.startsWith('padding') 会匹配所有以 padding 开头的属性,包括 paddingBlockpaddingInline 等逻辑属性,请确认这是预期行为。

如果确认只需处理 padding,建议在注释中补充说明原因:

💡 建议的注释改进
-            // 如果是 padding 属性,并且值为 undefined,则转换为 0
+            // 如果是 padding 属性,并且值为 undefined/null,则转换为 0
+            // 注意:目前只处理 padding,其他属性(如 margin)暂不需要此转换
             if (key.startsWith('padding') && isNullable(actualValue)) {
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 168e6ec and 42d279e.

📒 Files selected for processing (1)
  • src/hooks/useStyleRegister.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
src/hooks/useStyleRegister.tsx (1)
src/util/index.ts (1)
  • isNullable (204-206)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: preview
🔇 Additional comments (1)
src/hooks/useStyleRegister.tsx (1)

18-18: LGTM!

正确引入了 isNullable 工具函数。

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/util/index.ts (1)

208-210: 考虑显式声明返回类型以提升类型安全性。

当前返回类型由 TypeScript 推断为 0 | T,但当 T 包含 null | undefined 时,实际返回值类型应为 0 | Exclude<T, null | undefined>。建议显式声明返回类型,避免下游使用时产生类型混淆。

♻️ 建议的修改
-export const normalizeValue = <T>(val: T) => {
-  return isNullable(val) ? 0 : val;
-};
+export const normalizeValue = <T>(val: T): T extends null | undefined ? 0 : T => {
+  return (isNullable(val) ? 0 : val) as T extends null | undefined ? 0 : T;
+};

或者使用更简洁的写法:

-export const normalizeValue = <T>(val: T) => {
-  return isNullable(val) ? 0 : val;
-};
+export const normalizeValue = <T>(val: T): 0 | Exclude<T, null | undefined> => {
+  return isNullable(val) ? 0 : val;
+};
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42d279e and 345711a.

📒 Files selected for processing (2)
  • src/hooks/useStyleRegister.tsx
  • src/util/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useStyleRegister.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: preview
🔇 Additional comments (1)
src/util/index.ts (1)

204-206: LGTM!

isNullable 类型守卫实现正确,能够准确识别 nullundefined 值。

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/useStyleRegister.tsx (1)

321-329: MULTI_VALUE 数组路径缺少相同的空值检查。

非 MULTI_VALUE 路径(第 326-328 行)添加了 isNonNullable 检查,但 MULTI_VALUE 数组路径(第 322-324 行)对数组元素没有应用相同的保护。如果数组包含 nullundefined 项,它们仍会被传递给 appendStyle

建议在数组迭代时也添加空值检查以保持一致性。

♻️ 建议修复
           if (
             typeof value === 'object' &&
             (value as any)?.[MULTI_VALUE] &&
             Array.isArray(actualValue)
           ) {
             actualValue.forEach((item) => {
-              appendStyle(key, item);
+              if (isNonNullable(item)) {
+                appendStyle(key, item);
+              }
             });
           } else {
             if (isNonNullable(actualValue)) {
               appendStyle(key, actualValue);
             }
           }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 345711a and 691933f.

📒 Files selected for processing (3)
  • src/hooks/useStyleRegister.tsx
  • src/util/index.ts
  • tests/index.spec.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/index.spec.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
src/hooks/useStyleRegister.tsx (1)
src/util/index.ts (1)
  • isNonNullable (204-206)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: preview
🔇 Additional comments (2)
src/util/index.ts (1)

203-206: LGTM!

类型守卫实现正确,使用 TypeScript 泛型和类型谓词进行类型收窄,是常见且标准的工具函数模式。

src/hooks/useStyleRegister.tsx (1)

18-18: LGTM!

导入新增的 isNonNullable 工具函数,与现有导入保持一致的风格。

@li-jia-nan li-jia-nan changed the title fix: should convert undefined value to 0 fix: should skip appendStyle when value is null or undefined Jan 13, 2026
@li-jia-nan li-jia-nan merged commit 9bee8f5 into master Jan 13, 2026
9 checks passed
@li-jia-nan li-jia-nan deleted the padding-convert branch January 13, 2026 06:53
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.

3 participants