← 输入框|github.com|刷新
Skip to content

fix(vite): keep the rules after @layer, @container and other at-rules css can't parse - #11538

Merged
NathanWalker merged 2 commits into
mainfrom
fix/vite-css-at-rules
Oct 21, 2026
Merged

NathanWalker merged 2 commits into
mainfrom
fix/vite-css-at-rules

Conversation

@triniwiz

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

@nativescript/vite parses CSS with reworkcss css, which reads an at-rule it doesn't know as the start of a selector. The first @layer, @container, @starting-style, @property or @scope ends the parse, and every rule after it is lost (@property instead parses as a junk rule). Bootstrap 6 wraps its whole stylesheet in @layers and Tailwind 4 emits @layer and @property, so only the rules before the first one (78 of Bootstrap's 4,430) reach the app.

What is the new behavior?

normalizeCssAtRules() (helpers/css-ast.ts) rewrites the stylesheet before parseCssAst parses it, on both the app.css and the bundled-CSS paths:

  • @layer blocks are replaced with their rules. Top-level layers move ahead of the unlayered rules in layer order (first mention, including @layer a, b;), which is how the cascade orders them. A layer inside another at-rule is unwrapped where it is.
  • Every other at-rule css can't parse is dropped with its block, at any depth. Core only reads rules, @media, @keyframes and @import, so nothing it uses is lost.
  • Text outside those at-rules is kept byte for byte, and a stylesheet without them is returned unchanged.

A live HMR edit of app.css is sent to core as text and parsed on the device by css-tree, which does not stop at unknown at-rules but ignores layer nodes; flattening them there is a possible follow-up in core.

Tests: 10 cases in helpers/css-ast.spec.ts.

Each new test fails without the change. The @nativescript/vite suite (163 files) and tsc -p tsconfig.lib.json pass on the branch.

… css can't parse

The build turns app.css and the bundled component css into an AST with
`css` (reworkcss), which reads an at-rule it doesn't know as the start of a
selector and gives up there. One `@layer`, `@container`, `@starting-style`
or `@property` was enough to lose every rule after it. Bootstrap 6 wraps
its whole stylesheet in `@layer`s and Tailwind 4 emits `@layer` and
`@property`, so apps lost almost all of their styles in non-HMR builds and
on the first HMR load.

The stylesheet is now rewritten before it is parsed. `@layer` blocks are
replaced by their rules: top-level layers move ahead of the unlayered rules
in layer order (first mention, including `@layer a, b;`), as the cascade
orders them, and layers inside another at-rule are unwrapped in place.
Every other at-rule `css` doesn't know is removed with its block; core only
reads rules, `@media`, `@keyframes` and `@import`, so nothing it uses is
lost. Stylesheets without such at-rules are passed through unchanged.
@nx-cloud

nx-cloud Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 09ea542

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 50s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-15 20:43:36 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11538
npm i https://pkg.pr.new/@nativescript/vite@11538
npm i https://pkg.pr.new/@nativescript/webpack@11538

commit: 09ea542

@NathanWalker
NathanWalker merged commit 9d14812 into main Oct 21, 2026
10 checks passed
@NathanWalker
NathanWalker deleted the fix/vite-css-at-rules branch October 21, 2026 18:38
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