Conversation
packages/tailwindcss/src/index.ts
Outdated
| // could register new rules that include functions, and JS config files could | ||
| // also contain functions or plugins that use functions so we need to evaluate | ||
| // functions if either of those are present. | ||
| if (css.includes(THEME_FUNCTION_INVOCATION) || plugins.length > 0 || configs.length > 0) { |
There was a problem hiding this comment.
The theme() calls from utilities are not processed by this call to substituteFunctions. The call in build() handles that because the generated nodes are the ones that have theme().
This is purely required for the work where we're taking the config stuff and backfilling some values into the theme (which ultimately makes it into the "static" AST).
So maybe the comment could use some clarification.
There was a problem hiding this comment.
Though theme calls inside @utility would be processed here but that happens to be more of an optimization.
There was a problem hiding this comment.
Yeah, this is only for detecting wether addBase pushed stuff into the input CSS AST, right? The rest will exist only in the designSystem.
| // Arbitrary values (`text-[theme(--color-red-500)]`) and arbitrary | ||
| // properties (`[--my-var:theme(--color-red-500)]`) can contain function | ||
| // calls so we need evaluate any functions we find there that weren't in | ||
| // the source CSS. |
There was a problem hiding this comment.
see comment above but this is where theme() calls output by utilities (doing like addUtilities or matchUtilities) are processed.
| addBase({ | ||
| '.my-base-rule': { | ||
| color: 'theme(colors.red)', | ||
| 'outline-color': 'theme(colors.orange / 15%)', | ||
| 'background-color': 'theme(--color-blue)', | ||
| 'border-color': 'theme(--color-pink / 10%)', | ||
| }, | ||
| }) |
There was a problem hiding this comment.
We should probably also add an addUtility to test values inside utilities (since these won't be added to the initial CSS AST so it will be replaced at a different layer.
| addBase({ | |
| '.my-base-rule': { | |
| color: 'theme(colors.red)', | |
| 'outline-color': 'theme(colors.orange / 15%)', | |
| 'background-color': 'theme(--color-blue)', | |
| 'border-color': 'theme(--color-pink / 10%)', | |
| }, | |
| }) | |
| addBase({ | |
| '.my-base-rule': { | |
| color: 'theme(colors.red)', | |
| 'outline-color': 'theme(colors.orange / 15%)', | |
| 'background-color': 'theme(--color-blue)', | |
| 'border-color': 'theme(--color-pink / 10%)', | |
| }, | |
| }) | |
| addUtilities({ | |
| '.my-utility': { | |
| color: 'theme(colors.red)', | |
| }, | |
| }) |
packages/tailwindcss/src/index.ts
Outdated
| // could register new rules that include functions, and JS config files could | ||
| // also contain functions or plugins that use functions so we need to evaluate | ||
| // functions if either of those are present. | ||
| if (css.includes(THEME_FUNCTION_INVOCATION) || plugins.length > 0 || configs.length > 0) { |
There was a problem hiding this comment.
Yeah, this is only for detecting wether addBase pushed stuff into the input CSS AST, right? The rest will exist only in the designSystem.
a4f8a3c to
420a5ef
Compare
This PR fixes a bug where CSS
theme()functions were not evaluated when present in rules added by plugins, using either@pluginor registering a plugin in a JS config file.For example, prior to this PR the
theme()functions in this plugin would make it into the final CSS without being evaluated: