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: colorPalette is not defined #26395
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a4da6fa:
|
Size Change: 0 B Total Size: 797 kB ℹ️ View Unchanged
|
Codecov Report
@@ Coverage Diff @@
## master #26395 +/- ##
=======================================
Coverage 99.70% 99.70%
=======================================
Files 382 382
Lines 7344 7344
Branches 2008 2049 +41
=======================================
Hits 7322 7322
Misses 22 22 Continue to review full report at Codecov.
|
The |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
close #26290
close #23480
close #23412
💡 Background and solution
参考 #26290 里的重现(用法来自定制主题 里的方式三),当使用
@import "~antd/dist/antd.less"
引入样式时,在 lessOptions 的modifyVars
里添加 hack 字段如下。此时启动项目时会报
ReferenceError: colorPalette is not defined'
的错误:移除 hack 字段,错误消失。这段 hack 代码来自于:https://unpkg.com/antd/dist/theme.js
但是这段代码不能移除,当使用 babel-plugin-import 引入样式时(而不是
@import "~antd/dist/antd.less"
),如果没有这段 hack,同样会报ReferenceError: colorPalette is not defined
。继续排查发现是下面两段代码会导致问题,移除这两个 mixin 调用后错误消失。
ant-design/components/tree/style/index.less
Line 12 in 875e190
ant-design/components/tree-select/style/index.less
Line 39 in 875e190
进一步排查,发现只要在 mixin 中应用了
@primary-1
这样会使用 colorPalette 做色彩计算的变量,就会导致问题。寻找解决方案的过程中试验出,如果 mixin 的调用不在顶层,而在一个 selector 里面时,错误也会消失。
看上去和 less 解析 mixin 的顺序有关系,具体原因没有排查。
解决方式就是将
.antTreeFn()
里的一层包裹拿到调用的外面。📝 Changelog
colorPalette is not defined
when customize theme in some situation.colorPalette is not defined
的问题。☑️ Self Check before Merge