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
Allow spaces in the arguments of a CSS mixin in @apply - #20725
@apply with a CSS mixin threw "You cannot use @apply with both mixins and utilities" as soon as the mixin arguments had a space, e.g. @apply --card(red, 2rem). The params were split on every whitespace, so --card(red, was seen as a mixin and 2rem) as a utility.
The params are now split with segment, so whitespace inside parens, brackets, braces and strings is kept in the same part. The dependency scan and the circular dependency check use the same split, so a mixin argument like card in @utility card { @apply --card({ red, card }, 2rem); } is not read as a utility. A list of valid utilities splits the same way as before.
Added @apply --my-mixin-1(red, 2rem) and @apply --my-mixin-1({ 1px, 2px }, 3px) to the existing "should be usable with CSS mixins" test in index.test.ts. It fails without this change and passes with it.
Added a test with @apply --card({ red, card }, 2rem) inside @utility card. It fails with a circular dependency error without this change.
pnpm vitest run in packages/tailwindcss: all tests pass.
Review was skipped as selected files did not have any reviewable changes.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 2707c393-a941-409c-97c5-1087b7ad13b2
Commits
Reviewing files that changed from the base of the PR and between 3061bb5 and 736dcab.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
@apply now uses splitApplyParams for candidate collection, dependency resolution, and circular-dependency checks. The parser keeps whitespace within dashed identifiers and tracks source offsets. Tests cover spaced CSS mixin arguments, mixins in custom utilities, mixed mixin-and-utility errors, and utility candidates split at spaces in brackets, parentheses, and strings. The changelog records the fix.
Severity of issue fixed: Medium
Merge Risk: Minimal · previous review 3061b
This change lets @apply keep CSS mixin calls whose arguments contain spaces intact instead of misreading them as utilities. It has tests for the main cases and no remaining concrete merge risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title states the main change: @apply now accepts spaces inside CSS mixin arguments. The changeset splits @apply params with segment, keeps whitespace inside parens, brackets, braces, and str…
Description check
The description explains the bug, the new splitting approach, the effect on the dependency scan and circular-dependency check, and the test plan. It relates directly to the changeset in apply.ts and i…
Linked Issues check
[#20724] The issue requires @apply --card(red, 2rem) and @apply --card({ 1px, 2px }, 3px) to keep the CSS mixin without the "both mixins and utilities" error. It also requires utility lists to spl…
Out of Scope Changes check
The whole-PR apply.ts diff changes only @apply parameter tokenization in substituteAtApply and resolveApplyDependencies, plus the offset accounting that the new tokenization needs, and adds th…
Full details: Title check
Explanation
The title states the main change: @apply now accepts spaces inside CSS mixin arguments. The changeset splits @apply params with segment, keeps whitespace inside parens, brackets, braces, and strings, and adds tests for mixin arguments with spaces. The title matches the primary fix.
Full details: Description check
Explanation
The description explains the bug, the new splitting approach, the effect on the dependency scan and circular-dependency check, and the test plan. It relates directly to the changeset in apply.ts and index.test.ts.
Full details: Linked Issues check
Explanation
[#20724] The issue requires @apply --card(red, 2rem) and @apply --card({ 1px, 2px }, 3px) to keep the CSS mixin without the "both mixins and utilities" error. It also requires utility lists to split as before. I read the whole-PR apply.ts diff (merge base to head). The new splitApplyParams generator replaces whitespace with spaces, splits with segment(..., ' '), and yields dashed identifiers whole through isDashedIdent. Other parts split at each whitespace, as the old split(/\s+/g) did. Offsets advance by one per separator, including empty parts. substituteAtApply (candidate collection and offset tracking) and resolveApplyDependencies (dependency scan and circular check) both use this helper. So --card(red, 2rem) and --card({ 1px, 2px }, 3px) stay one mixin part, and the card word inside @utility card is not read as a utility. Utility candidates such as bg-[rgb(1, 2, 3)] still split at whitespace, so their behavior is unchanged. The test-file additions were taken from the PR description and the summary, not from a full diff read. I did not run the test suite. The previous assessment described an earlier split-everything approach. Its conclusion still holds for the current refined logic that I read.
Full details: Out of Scope Changes check
Explanation
The whole-PR apply.ts diff changes only @apply parameter tokenization in substituteAtApply and resolveApplyDependencies, plus the offset accounting that the new tokenization needs, and adds the splitApplyParams and isDashedIdent helpers. All of these serve #20724. The summary reports test additions in index.test.ts for mixin arguments, and a changelog entry in .changelog/apply-mixin-arguments-with-spaces.md. Both support the fix. The summary reports no changes to exported declarations. No unrelated change is demonstrated. Test-file and changelog contents were taken from the summary, not from a full diff read.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: fd954865-925d-4fcc-a4b6-aa96aadf498b
Commits
Reviewing files that changed from the base of the PR and between e811a49 and 3061bb5.
Files selected for processing: 2
packages/tailwindcss/src/apply.ts
packages/tailwindcss/src/index.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 368d14a8-a2e0-4b49-b364-6e6ebfa65916
Commits
Reviewing files that changed from the base of the PR and between b08bf83 and 058f4c3.
Files selected for processing: 3
.changelog/apply-mixin-arguments-with-spaces.md
packages/tailwindcss/src/apply.ts
packages/tailwindcss/src/index.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The previous commits split all `@apply` params with `segment`. That also
kept the spaces inside the brackets, parens and strings of utilities, so
`@apply bg-[rgb(1, 2, 3)]`, `@apply [margin:1px 2px]` and
`@apply content-['a b']` started to compile. No class in a template can
contain a space, so `@apply` should not allow it either.
`splitApplyParams` now keeps a part whole only when it is a dashed ident
(a CSS mixin, like `--card(red, 2rem)`). Every other part is split at
each whitespace, as before. All three readers of the params (the
dependency scan, the circular dependency check and the substitution) use
it, with the offsets of each part for the source maps.
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
@applywith a CSS mixin threw "You cannot use@applywith both mixins and utilities" as soon as the mixin arguments had a space, e.g.@apply --card(red, 2rem). The params were split on every whitespace, so--card(red,was seen as a mixin and2rem)as a utility.The params are now split with
segment, so whitespace inside parens, brackets, braces and strings is kept in the same part. The dependency scan and the circular dependency check use the same split, so a mixin argument likecardin@utility card { @apply --card({ red, card }, 2rem); }is not read as a utility. A list of valid utilities splits the same way as before.Fixes #20724
Test plan
@apply --my-mixin-1(red, 2rem)and@apply --my-mixin-1({ 1px, 2px }, 3px)to the existing "should be usable with CSS mixins" test inindex.test.ts. It fails without this change and passes with it.@apply --card({ red, card }, 2rem)inside@utility card. It fails with a circular dependency error without this change.pnpm vitest runinpackages/tailwindcss: all tests pass.pnpm changelog checkpasses.