Fix @utility to accept already-escaped utility names#19691
Fix @utility to accept already-escaped utility names#19691shtse8 wants to merge 1 commit intotailwindlabs:mainfrom
Conversation
When using CSS linters like Biome that require proper CSS escaping, writing `@utility my\/utility` (with the slash escaped as `\/`) is the correct way to express a utility name containing a forward slash. Previously, Tailwind would throw an error: `@utility my\/utility` defines an invalid utility name. Utilities should be alphanumeric and start with a lowercase letter. This is because the CSS parser preserves raw escape sequences and the validator did not account for CSS escape sequences in utility names. The fix unescapes the utility name (using the same CSS unescape implementation that already exists in `utils/escape.ts`) before validating and registering it, so that: - `@utility my\/utility` (escaped) is treated as equivalent to `@utility my/utility` (unescaped) - The utility is registered under the unescaped name so that candidates like `my/utility` in HTML continue to match correctly - No double-escaping occurs: the generated CSS selector is `.my\/utility` in both cases Fixes tailwindlabs#19607
|
No actionable comments were generated in the recent review. 🎉 WalkthroughThe pull request adds support for handling CSS escape sequences in 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
|
Hey! I appreciate the PR but please only open PRs for issues that don't have an open PR already. Going to close this in favor of the PR that solves this issue already: #19626 |
This PR fixes a bug where using CSS escape sequences in
@utilitynames would throw a validation error, even though escaping is required by strict CSS linters like Biome.Problem
Writing
@utility my/utilityis technically invalid CSS (an unescaped/in an identifier). Strict linters like Biome will flag this with a parse error. The correct CSS syntax is@utility my\/utility(with the slash escaped).However, Tailwind currently throws:
This is because the CSS parser preserves raw escape sequences in
node.params, and the validator didn't account for CSS escape sequences.Fix
Unescape the utility name before validation and registration in
createCssUtility, using the existingunescapeutility fromutils/escape.ts. This means:@utility my\/utility(escaped) is accepted and treated as equivalent to@utility my/utility(unescaped)my/utility) so that candidates in HTML continue to match correctly.my\/buttonin both casesTest plan
@utility my\/utilitygenerates.my\/utility { … }Fixes #19607