You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Don't treat the / in theme keys like width.1/2 as an opacity modifier - #20604
In v4, theme() always reads the part after the last / as an opacity modifier. For theme keys that contain a /, like the fraction keys in the default compat theme, theme(width.1/2) resolves width.1 instead and applies 2 as the alpha:
.half {
width:theme(width.1/2);
}
compiles to width: color-mix(in oklab, 0.25rem 200%, transparent) on 4.3.3 and on main. The plugin API's theme('width.1/2') returns the same value, while theme('width')['1/2'] returns the expected width. v3.4.19 compiles the CSS above to width: 50%, and the 4.0 changelog lists referencing --width-1\/2 as theme('width.1/2') as supported (#14739), so this mostly affects CSS and plugins carried over from v3.
createThemeFn now resolves the full path first and only splits off the last segment as a modifier when the full path doesn't resolve. theme(colors.red.500/50%) and the existing theme(colors.red.500 / 75%) test behave as before.
Test plan
Added theme(width.1/2) to css-functions.test.ts (a --width-1\/2 CSS variable, inset.1/3 from the default compat theme, and a colors.red.500/50% control) and a plugin API test in compat/plugin-api.test.ts (CSS variable, JS config extend, default compat theme, and a color control). Both fail on main with the color-mix(...) values and pass with this change.
npx vitest run in packages/tailwindcss: 44 files, 5164 passed, 1 skipped.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Walkthrough
createThemeFn now resolves the complete theme path before treating a trailing slash-separated segment as an opacity modifier. If the complete path does not resolve, it extracts the suffix and resolves the base path. New tests cover slash-containing CSS and JavaScript theme keys, fallback values, and color opacity.
Priority: ⬇️ Low
Merge Risk:⚪ Minimal · up to bac72
No actionable merge-blocking risk was found in the reviewed change.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main change: preventing slash-containing theme keys such as width.1/2 from being treated as opacity modifiers.
Description check
The description directly explains the bug, implementation, regression coverage, compatibility behavior, and reported test results.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
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
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.
Summary
In v4,
theme()always reads the part after the last/as an opacity modifier. For theme keys that contain a/, like the fraction keys in the default compat theme,theme(width.1/2)resolveswidth.1instead and applies2as the alpha:compiles to
width: color-mix(in oklab, 0.25rem 200%, transparent)on 4.3.3 and onmain. The plugin API'stheme('width.1/2')returns the same value, whiletheme('width')['1/2']returns the expected width. v3.4.19 compiles the CSS above towidth: 50%, and the 4.0 changelog lists referencing--width-1\/2astheme('width.1/2')as supported (#14739), so this mostly affects CSS and plugins carried over from v3.createThemeFnnow resolves the full path first and only splits off the last segment as a modifier when the full path doesn't resolve.theme(colors.red.500/50%)and the existingtheme(colors.red.500 / 75%)test behave as before.Test plan
theme(width.1/2)tocss-functions.test.ts(a--width-1\/2CSS variable,inset.1/3from the default compat theme, and acolors.red.500/50%control) and a plugin API test incompat/plugin-api.test.ts(CSS variable, JS configextend, default compat theme, and a color control). Both fail onmainwith thecolor-mix(...)values and pass with this change.npx vitest runinpackages/tailwindcss: 44 files, 5164 passed, 1 skipped.prettier --checkon the changed files passes.