fix: preserve arbitrary values using CSS variables during Tailwind v4… #19189
+31
−9
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.
Description
This PR focuses on fixing incorrect arbitrary utility conversions introduced during the Tailwind v4 migration.
Some utilities using CSS variables like
gap-[var(--gap)]were mistakenly transformed intogap-(--gap)by the upgrade CLI, causing runtime and style mismatches.This update restores proper handling for CSS variable–based arbitrary values to ensure accurate conversion and consistent styling.
Changes
Early Guard for Complex Arbitrary Values
arbitraryUtilities, when the candidate isfunctional + arbitrary, conversion is skipped if the raw value containsvar(),calc(), spaces, commas, or slashes.gap-[var(--gap)]→gap-(--gap).String Normalization
valueStr = String(value)for consistent parsing and formatting.Complex Value Handling
isComplexis true, do not attempt bare-value replacements; only emit the bracketed arbitrary form (${root}-[${valueStr}]).Modifier Serialization
printModifier()when emitting classes with modifiers to ensure correct formatting.Storage/Signature Access (No Behavior Change)
designSystem.storage[PRE_COMPUTED_UTILITIES_KEY | UTILITY_SIGNATURE_KEY].get(options.signatureOptions).designSystem.storage[SPACING_KEY].Motivation
The Tailwind v4 migration tool (
@tailwindcss/upgrade) introduced incorrect transformations for arbitrary utilities using CSS variables, leading to broken layouts.This fix ensures the migration process safely ignores complex or variable-based values and preserves valid classnames for reliable build output.
Breaking Changes
None.
This patch only restores correct handling for arbitrary utility parsing during the migration process.
Before/After