Skip to content

fix: keep media queries for every rule of a block - #686

Merged
Brentlok merged 1 commit into
uni-stack:mainfrom
juliusmarminge:fix/media-block-sibling-queries
Sep 23, 2026
Merged

Brentlok merged 1 commit into
uni-stack:mainfrom
juliusmarminge:fix/media-block-sibling-queries

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Tailwind groups every utility of a variant into one shared media block — all ios: utilities land in a single @media ios { ... }, all sm: utilities in one width block. The processor's media branch pushed the block's media queries onto declarationConfig, parsed the first child, then reset the config after every child. So only the first utility of a block kept the block's queries:

  • every android: utility past the first applied on iOS (and vice versa) — in T3 Code this shipped android:font-mono, android:px-4 etc. into the iOS bundle unguarded;
  • every utility past the first of a width breakpoint applied below its breakpoint;
  • the bug is present in 1.11.0 and current main.

The added tests fail on main against the existing harness (real compile through compileCSS, iOS test env): android-block-second resolves paddingTop: 8 on iOS, wide-block-second resolves paddingTop: 5 at width 390.

The fix

Feed each sibling rule the block's media queries explicitly instead of relying on leftover state, and restore the outer config after the block rather than assigning a fresh one — so media rules nested inside a class rule (@utility bodies with @variant, nested breakpoints) keep writing into the enclosing class, exactly as before.

Tests

tests/test.css gains a two-utility @media ios block, a two-utility @media android block, a two-utility width block, and a nested @media inside a class rule; media-queries.test.ts asserts every utility of each block stays guarded. Native suite: 48 files / 178 tests pass (bun run test:native), web suite green, tsc --noEmit, oxlint, dprint clean.


Discovered while auditing T3 Code's mobile styles; we currently ship this as a pnpm patch (pingdotgg/t3code#13172) and will drop it in favor of this once released.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed media query handling so all rules within a media block consistently retain the correct platform and width conditions.
    • Corrected media queries nested within class rules to apply their intended styles.
  • Tests

    • Added coverage for grouped platform media blocks, width breakpoints, and nested media queries.

Tailwind groups all utilities of a variant into one @media block
(every ios: utility shares `@media ios { ... }`). The processor pushed
the block's queries onto the config, then reset the config after each
sibling rule, so only the first utility of a block kept them. Every
later utility compiled without the block's guard: `android:` utilities
in a second position applied on iOS, utilities past the first of a
width breakpoint applied below it, and so on.

Feed each sibling the block's media queries explicitly, and reset to
the outer config rather than a fresh one after the block so media rules
nested inside a class rule keep writing into that class.
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7d9024f1-c2ba-447b-8236-f3d24f22f6e3

📥 Commits

Reviewing files that changed from the base of the PR and between ba7ac68 and ee6e1bc.

📒 Files selected for processing (3)
  • packages/uniwind/src/bundler/css-processor/processor.ts
  • packages/uniwind/tests/native/styles-parsing/media-queries.test.ts
  • packages/uniwind/tests/test.css

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The media rule parser now preserves block queries for every nested rule and restores the outer declaration configuration. Tests and CSS fixtures cover platform blocks, width breakpoints, and media rules nested in class rules.

Changes

Media Query Parsing

Layer / File(s) Summary
Preserve media query state
packages/uniwind/src/bundler/css-processor/processor.ts
parseRuleRec merges outer and block media queries for each nested rule, then restores the outer configuration.
Cover media query combinations
packages/uniwind/tests/test.css, packages/uniwind/tests/native/styles-parsing/media-queries.test.ts
Tests cover multiple platform rules, shared width breakpoints, and nested class media rules at different widths.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: brentlok

Merge Risk: ⚪ Minimal · up to ee6e1

The media-query state correction is covered across the affected platform, breakpoint, and nested-rule cases. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving media queries for every rule within a shared media block.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 23, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule issues were identified.

Summary

This PR corrects native CSS media-block context handling so every sibling rule retains the block’s platform and breakpoint conditions while nested media rules preserve their enclosing class context.

  • Captures and restores the enclosing declaration configuration around media blocks.
  • Reapplies the combined media-query context independently to every child rule.
  • Adds native regression coverage for platform blocks, width blocks, and media nested within a class.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Enter media block] --> B[Capture enclosing declaration config]
    B --> C[Combine enclosing and block media queries]
    C --> D{For each child rule}
    D --> E[Create fresh config from enclosing context]
    E --> F[Attach combined media queries]
    F --> G[Parse child rule]
    G --> D
    D -->|All children parsed| H[Restore enclosing declaration config]
Loading

Reviews (1) · Last reviewed commit: "fix: keep media queries for every rule o..."

@Brentlok
Brentlok merged commit 31d91fc into uni-stack:main Sep 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants