fix(cli): correctly nest @media rules inside parent selectors (#10375) - #10384
Open
mrlexcoder wants to merge 1 commit into
Open
fix(cli): correctly nest @media rules inside parent selectors (#10375)#10384mrlexcoder wants to merge 1 commit into
mrlexcoder wants to merge 1 commit into
Conversation
…-ui#10375) When a registry item defines nested at-rules like @media inside a selector (e.g., body), the PostCSS merger was incorrectly appending them as siblings to the parent at-rule instead of nesting them inside the current rule. This caused syntax errors like 'Unexpected end of input' in Next.js. Fixed by detecting nested at-rules with bodies and creating them inside the current rule, then recursively processing their content. Fixes shadcn-ui#10375
Contributor
|
@mrlexcoder is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
When a registry item (e.g.,
registry:style) defines nested at-rules like@mediainside a selector object (e.g.,bodyinside@layer base), the PostCSS merger in the CLI incorrectly appends those@mediablocks as siblings to the parent at-rule instead of nesting them inside the current rule.Example registry item:
{ "name": "repro-nested-media", "type": "registry:style", "css": { "@layer base": { "body": { "--foo": "1rem", "@media (width >= 40rem)": { "--foo": "2rem" } } } } }Current (broken) output:
This causes "Unexpected end of input" errors in Next.js because the
@mediarule is orphaned outside thebodyselector.Expected output:
Root Cause
In
packages/shadcn/src/utils/updaters/update-css.ts, theprocessRulefunction handles nested objects (line 597-602). When it encounters a nested object property, it assumes it's a nested selector and callsprocessRule(parent, ...), which appends to the parent at-rule instead of the current rule.The code didn't check if the nested property is an at-rule (starts with
@) with a body.Solution
Added logic to detect nested at-rules with bodies:
prop.startsWith("@")and has a non-empty object valuerule(notparent)Changes
packages/shadcn/src/utils/updaters/update-css.ts- UpdatedprocessRulefunction (lines 597-624)Testing
With this fix:
@mediarules are correctly placed inside their parent selectors@media,@supports,@container, etc.)Related
Fixes #10375
Submitted by: @mrlexcoder