parcel-bundler / parcel-bundler/lightningcss

bug: `@property` rules remain nested in selector when targeting Chrome ≥120

Open
#962 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
7.7k
Forks
302
PR merge metrics
No merged PRs in 30d

Description

We ran into this issue while working on @property support in next-yak. It was reported by a user migrating from emotion in DigitecGalaxus/next-yak#325

According to the CSS spec, @property rules must appear at the top level of a stylesheet.

They must not be nested inside selectors.

LightningCSS currently handles this differently depending on Chrome version:

  • For Chrome ≤119: @property rules are correctly hoisted to the root level Playground Link ✅ works
  • For Chrome ≥120: @property rules incorrectly stay nested in selectors Playground Link ❌ broken
Reproduction

When a user writes:

.example {
  @property --angle {
    syntax: '<angle>';
    inherits: true;
    initial-value: 0turn;
  }
  animation: spin 3s linear infinite;
}

Output for Chrome ≤119 (correct):

@property --angle {
  syntax: '<angle>';
  inherits: true;
  initial-value: 0turn;
}

.example {
  animation: spin 3s linear infinite;
}

Output for Chrome ≥120 (broken):

.example {
  @property --angle {
    syntax: '<angle>';
    inherits: true;
    initial-value: 0turn;
  }
  
  animation: spin 3s linear infinite;
}

@Mad-Kat found out that in LightningCSS the CSS nesting feature being automatically disabled when targeting Chrome ≥120

https://github.com/parcel-bundler/lightningcss/blob/6c465c123deb549dfb45fd3558f25dca0dbde0d6/src/compat.rs#L1395-L1410

Expected Behavior

@property rules should always be hoisted to the root level, regardless of target Chrome version or nesting feature status.

In Chrome's actual implementation, @property rules don't work when nested inside selectors (as seen in this CodePen example).

This means that LightningCSS generates broken CSS

If you briefly outline how this issue should be solved we can create a pull request

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading src/compat.rs around lines 1395-1410 and compare the Chrome ≤119 and ≥120 reproduction outputs. Trace how the nesting feature status affects handling of @property rules. Done means @property is hoisted to the stylesheet root for both target ranges, with the reported reproduction no longer producing nested output.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, rust
Domain
compilers, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.