Repository navigation
Canonicalization: keep the -- when dropping the theme prefix of a variable - #20765
Open
RobinMalfait wants to merge 2 commits into
Open
RobinMalfait wants to merge 2 commits into
RobinMalfait wants to merge 2 commits into
Conversation
`resolveVariablesInValue` drops the theme prefix from a variable before it looks up its value. The slice also dropped the leading `--`, so with `@theme prefix(tw)` it looked up `spacing` instead of `--spacing`. A path without `--` is a legacy path for the compat layer, so the first such lookup switched the design system to full plugin support. That replaces `resolveThemeValue` with a slower version that goes through `theme()` for each lookup after it. The output stayed the same, but the first canonicalization of `tw:p-4` on a fresh design system with the default theme took ~2.4s instead of ~0.77s. The slice came in with 551bbed "add signatures", in #17831.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a slow path in canonicalization when you use a theme prefix (e.g.
@import 'tailwindcss' prefix(tw)).resolveVariablesInValuedrops the theme prefix from a variable before it looks up the value. The slice also dropped the leading--:For the compat layer, a path without
--is a legacy path (likecolors.red.500). So the first such lookup calledupgradeToFullPluginSupport, which replacesdesignSystem.resolveThemeValuewith a version that goes throughtheme()→readFromCss→Theme.namespace()for each lookup after it.The fix keeps the
--:The names in
seenand in the inlined theme variables of a signature now have the--too. Those names are only compared with each other, so this changes nothing else.History
The slice came in with 551bbed "add signatures" in #17831. #19171 moved the code, but kept the line as is. The code comment says only "The internal variable doesn't have the prefix", and no review comment or changelog entry mentions it, so the missing
--looks like an oversight. I found no issue or PR that reports this.Output
The output stays the same. With the default theme, the bare key and the
--variable resolve to the same value for each of the 419 theme variables, so this is a performance fix only. To make sure, I compared the output before and after the fix:var(--tw-…), collapses liketw:w-[1rem] tw:h-[1rem]→tw:size-4, etc.), with 6 theme setups (default, extra@themevalues,@theme inline,@theme reference,@theme static, a custom--spacing): 216 results, all the same.@configthat extends the theme in JS (full plugin support is already on there): the same.getClassList(), withcollapse: true: the same.Performance
Measured with the built
dist, on a fresh design system with the full default theme andprefix(tw), Node 24, Apple M5 Pro. Each run is a new process.canonicalizeCandidates(['tw:p-4']), first call (5 runs)getClassList(),collapse: trueWithout a prefix, the first call takes 734–829 ms, so a prefix no longer adds a cost.
Test plan
canonicalize-candidates.test.tsthat canonicalizes prefixed candidates and checks thatdesignSystem.resolveThemeValueis still the same function after it, so the compat layer did not switch to full plugin support. It fails without the fix (the output is the same), and passes with it.pnpm vitest runinpackages/tailwindcss: all tests pass.