Skip to content

feat: support function type for extraCssVarPrefixCls to dynamically resolve prefixes#37

Merged
zombieJ merged 1 commit intomasterfrom
feat/dynamic-extra-prefix-cls
Feb 9, 2026
Merged

feat: support function type for extraCssVarPrefixCls to dynamically resolve prefixes#37
zombieJ merged 1 commit intomasterfrom
feat/dynamic-extra-prefix-cls

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 9, 2026

Allow extraCssVarPrefixCls to accept a function that receives { prefixCls, rootCls } and returns a string array. This enables dynamic generation of CSS variable scope names based on runtime values.

Summary by CodeRabbit

发布说明

  • New Features

    • extraCssVarPrefixCls 现已支持函数形式,可基于运行时信息动态生成 CSS 变量前缀类,兼容先前的静态数组用法。
  • Tests

    • 新增测试覆盖函数形式的 extraCssVarPrefixCls,验证最终生成的 CSS 选择器与预期一致。

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zombieJ, 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 introduces a significant enhancement to the genStyleUtils function by allowing the extraCssVarPrefixCls option to accept a function. This change provides greater flexibility, enabling developers to dynamically generate CSS variable scope names based on runtime prefixCls and rootCls values, moving beyond static string array configurations.

Highlights

  • Dynamic extraCssVarPrefixCls: The extraCssVarPrefixCls option now supports a function type, allowing for dynamic generation of CSS variable scope names.
  • Function Signature: The new function type for extraCssVarPrefixCls receives an object { prefixCls, rootCls } as an argument and is expected to return a string array.
  • Implementation Update: The genStyleUtils function has been updated to resolve extraCssVarPrefixCls dynamically, checking if it's a function before processing.
  • New Test Case: A new test case has been added to tests/extraCssVarPrefixCls.test.tsx to validate the correct behavior of the function-based extraCssVarPrefixCls.

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

Changelog
  • src/util/genStyleUtils.ts
    • Extended the extraCssVarPrefixCls type definition to include a function signature (info: { prefixCls: string; rootCls: string }) => string[].
    • Implemented logic within genStyleUtils to dynamically resolve extraCssVarPrefixCls if it is a function, using the provided prefixCls and rootCls.
  • tests/extraCssVarPrefixCls.test.tsx
    • Added a new test case to confirm that extraCssVarPrefixCls correctly processes and applies dynamically generated prefixes when a function is used.
Activity
  • The pull request introduces a new feature (feat) to allow dynamic resolution of extraCssVarPrefixCls.
  • The author zombieJ has provided a clear description of the change and its purpose.
  • No other review comments or activities are available in the provided context.
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.

@zombieJ zombieJ changed the title feat: support function type for extraCssVarPrefixCls to dynamically r… feat: support function type for extraCssVarPrefixCls to dynamically resolve prefixes Feb 9, 2026
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.39%. Comparing base (d68e958) to head (7561e0e).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #37      +/-   ##
==========================================
+ Coverage   90.26%   90.39%   +0.12%     
==========================================
  Files          11       11              
  Lines         298      302       +4     
  Branches       71       74       +3     
==========================================
+ Hits          269      273       +4     
  Misses         29       29              

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

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

概述

extraCssVarPrefixCls 添加了函数形式支持:类型从 string[] 扩展为 string[] | ((info: { prefixCls: string; rootCls: string }) => string[]),运行时会在提供函数时以 { prefixCls, rootCls } 调用并使用返回的数组构建 CSS 变量前缀类。

变更项

Cohort / File(s) Summary
核心实现
src/util/genStyleUtils.ts
扩展 extraCssVarPrefixCls 的类型签名为 string[] | ((info: { prefixCls: string; rootCls: string }) => string[]),并在运行时解析函数返回值以生成额外的 CSS 变量前缀类;保留对静态数组的向后兼容处理。
测试覆盖
tests/extraCssVarPrefixCls.test.tsx
新增测试,验证当 extraCssVarPrefixCls 为函数时能正确返回前缀数组并生成对应的容器/包装选择器(例如 .<prefix>-container, .<rootCls>-wrapper)。

代码审查工作量估计

🎯 2 (Simple) | ⏱️ ~10 分钟

🐰 我以小足轻点代码间,
将静态数组变为运行函;
前缀绽放在样式里,
测试为我把真相念,
小兔跳跃,喜讯传。

🚥 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 标题清晰准确地总结了此次变更的核心改动:为 extraCssVarPrefixCls 添加函数类型支持以实现动态前缀解析。

✏️ 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 feat/dynamic-extra-prefix-cls

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/util/genStyleUtils.ts (1)

220-229: 函数类型的运行时解析逻辑正确,但每次渲染都会重新调用函数。

extraCssVarPrefixCls 为函数时,每次渲染都会执行 extraPrefixCls({ prefixCls, rootCls })。如果该函数每次返回新的数组引用(即使内容相同),可能导致 useCSSVar 内部产生不必要的重复计算或样式注册。

可以考虑用 useMemo 包裹解析逻辑,以 prefixClsrootCls 作为依赖项:

♻️ 可选优化:memoize 解析结果
-      // Resolve function type to get dynamic extra prefix
-      const extraPrefixCls = options?.extraCssVarPrefixCls;
-      const resolvedExtraPrefixCls =
-        typeof extraPrefixCls === 'function'
-          ? extraPrefixCls({ prefixCls, rootCls })
-          : extraPrefixCls;
-
-      const cssVarCls = useCSSVar(
-        resolvedExtraPrefixCls?.length ? [rootCls, ...resolvedExtraPrefixCls] : rootCls,
-      );
+      // Resolve function type to get dynamic extra prefix
+      const extraPrefixCls = options?.extraCssVarPrefixCls;
+      const cssVarScope = useMemo(() => {
+        const resolvedExtraPrefixCls =
+          typeof extraPrefixCls === 'function'
+            ? extraPrefixCls({ prefixCls, rootCls })
+            : extraPrefixCls;
+        return resolvedExtraPrefixCls?.length
+          ? [rootCls, ...resolvedExtraPrefixCls]
+          : rootCls;
+      }, [prefixCls, rootCls, extraPrefixCls]);
+
+      const cssVarCls = useCSSVar(cssVarScope);

不过如果 useCSSVar 内部已经有适当的缓存/去重机制(如 useCSSVarRegister 基于 path 做 key),则当前实现也完全可以接受。


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.

Copy link
Contributor

@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 adds support for a function type for extraCssVarPrefixCls to enable dynamic CSS variable scopes. The implementation is straightforward, includes documentation updates and a new test case. A security review of src/util/genStyleUtils.ts and tests/extraCssVarPrefixCls.test.tsx found no vulnerabilities, though there is one minor suggestion regarding code consistency.

return (prefixCls: string, rootCls: string = prefixCls) => {
const hashId = useStyle(prefixCls, rootCls);

// 支持 function 类型,动态解析 extraCssVarPrefixCls
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This inline comment is in Chinese, while other implementation comments in this file are in English. To maintain consistency and ensure the code is easily understood by all contributors, it's best to use a single language for inline comments. Since the code that follows is quite self-descriptive, this comment can be safely removed.

…esolve prefixes

Allow extraCssVarPrefixCls to accept a function that receives { prefixCls, rootCls }
and returns a string array. This enables dynamic generation of CSS variable scope
names based on runtime values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zombieJ zombieJ force-pushed the feat/dynamic-extra-prefix-cls branch from 491a7d8 to 7561e0e Compare February 9, 2026 08:30
@zombieJ
Copy link
Member Author

zombieJ commented Feb 9, 2026

@gemini-code-assist CR again

Copy link
Contributor

@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 introduces a valuable enhancement by allowing extraCssVarPrefixCls to be a function, enabling dynamic generation of CSS variable prefixes. The implementation is clean, well-documented with an updated JSDoc example, and includes a new test case that thoroughly validates the new functionality. The code quality is excellent, and the changes are logical and easy to follow. I have no concerns with this pull request.

@zombieJ zombieJ merged commit 415a9e3 into master Feb 9, 2026
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.

1 participant