Skip to content

Add support for @starting-style rules#1566

Merged
askoufis merged 5 commits intovanilla-extract-css:masterfrom
lfantone:master
Dec 15, 2025
Merged

Add support for @starting-style rules#1566
askoufis merged 5 commits intovanilla-extract-css:masterfrom
lfantone:master

Conversation

@lfantone
Copy link
Contributor

@lfantone lfantone commented Apr 5, 2025

This pull request adds complete support for CSS Anchor positioning.
The update includes implementing all necessary types for rules as well as incorporating the new queries "@starting-style" and "@position-try", allowing for a better experience when using CSS anchor positioning rules

Closes #1521

EDIT: This PR will add support only for @starting-style rule. CSS Anchor position will be supported in a separate PR.

@changeset-bot
Copy link

changeset-bot bot commented Apr 6, 2025

🦋 Changeset detected

Latest commit: 592b8c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@vanilla-extract/css Minor
@vanilla-extract/compiler Patch
@vanilla-extract/integration Patch
@vanilla-extract/rollup-plugin Patch
@vanilla-extract/vite-plugin Patch
@vanilla-extract/esbuild-plugin Patch
@vanilla-extract/jest-transform Patch
@vanilla-extract/parcel-transformer Patch
@vanilla-extract/webpack-plugin Patch
@vanilla-extract/next-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mjanner
Copy link

mjanner commented Apr 30, 2025

Is this getting any attention?

@mettson
Copy link

mettson commented May 7, 2025

I would love to get this merged as soon as possible! Anyone who can review this PR?

@askoufis
Copy link
Contributor

askoufis commented May 8, 2025

@lfantone Thanks for the PR! I have a couple of requests for this PR:

  • I would prefer the @starting-style feature be implemented in a separate PR to the @position-try feature, primarily to facilitate an easier review
  • I appreciate that we don't have a contribution guide to make it easier to find where tests should be added, but we generally add new syntax to the fixtures/features/src/features.css.ts file in order to test it out, and update our snapshot tests accordingly. These are our E2E tests.
  • The CSS generated by your implementation of @position-try doesn't align with the syntax defined in the spec. Specifically, your implementation results in selectors being placed inside the @position-try rule, whereas the spec dictates that only declarations are valid inside @position-try.
  • Additionally, while it's not mentioned in the spec that @position-try rules can be nested inside other at-rules (e.g. @media), it makes sense that this should be possible, and [css-anchor-position] Be more nuanced about last @position-try winning w3c/csswg-drafts#11080 seems to suggest this. Honestly given that this spec is still in draft and doesn't even seem complete makes me hesitant to ship support for it in VE just yet. Happy to work through these issues in another PR though.
  • Additionally, VE doesn't currently have an API for generating bare dashed-idents (createVar only generates custom properties wrapped in var()). With CSS APIs appearing that use dashed-idents such as @font-palette-values and @color-profile, we'll need to look at how best to integrate dashed-idents into VE.

@lfantone
Copy link
Contributor Author

lfantone commented May 11, 2025

Thanks for the comment @askoufis, yeah you are right about splitting this into two different PR. I will convert this one to be the @starting-style implementation and then work on a another one 💪

Regarding the name for this properties, do you think we should go with @startingStyle and @posititonTry?

@lfantone
Copy link
Contributor Author

I think I manage to get the e2e test with Playwright but all the parcel cases fails with:

    {
      origin: '@parcel/transformer-css',
      message: 'Unknown at rule: @starting-style',
      name: 'SyntaxError',
      stack: undefined,
      codeFrames: undefined
    }

Which makes me wonder if parcel has support for this new css rule or if I'm missing something in some config.

@askoufis
Copy link
Contributor

I think I manage to get the e2e test with Playwright but all the parcel cases fails with:

    {
      origin: '@parcel/transformer-css',
      message: 'Unknown at rule: @starting-style',
      name: 'SyntaxError',
      stack: undefined,
      codeFrames: undefined
    }

Which makes me wonder if parcel has support for this new css rule or if I'm missing something in some config.

It should, though parcel uses lightningcss for its CSS bundling. Feel free to bump the parcel dep to the latest version (2.15.0) as I'd be very surprised if newer versions don't support @starting-style.

@lfantone lfantone force-pushed the master branch 2 times, most recently from ec4bbd9 to efc89b4 Compare May 12, 2025 07:34
@lfantone
Copy link
Contributor Author

PR updated!

There were two different parcel versions installed, one in the test-cases packages and another from the parcel-transformer. Once I upgraded both, it worked!

Let me know if there is anything else that should be addressed

@askoufis
Copy link
Contributor

@lfantone It looks like there's still some anchor positioning code lying around. Additionally it looks like you've accidentally deleted the starting-styles changeset instead of the anchor positioning changeset.

@lfantone lfantone changed the title Add support for CSS anchor positioning rules Add support for @starting-style rules May 16, 2025
@lfantone
Copy link
Contributor Author

lfantone commented May 18, 2025

Added two more PRs (#1589 & #1587) that implements the initial discussion about splitting the functionalities to make it easier to review.

Copy link
Contributor

@askoufis askoufis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're pretty close on this. A few tweaks and some unit tests and it should be ready to merge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the newer version of parcel is re-ordering and deduplicating CSS, resulting in these changes. They're not incorrect changes though, just calling them out.

export type FeatureQueries<StyleType> = Query<'@supports', StyleType>;
export type ContainerQueries<StyleType> = Query<'@container', StyleType>;
export type Layers<StyleType> = Query<'@layer', StyleType>;
export type StartingStyleQueries<StyleType> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on the StartingStyleQueries name? While the Queries suffix aligns with most of the other types, it doesn't really make sense since @starting-style isn't a query like @media or @container. It's more similar to @layer in that it declares something. Maybe it should just be called StartingStyle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good suggestion!

Comment on lines +647 to +650
if (root.type === 'local') {
this.transformSimplePseudos(root, rules, conditions);
this.transformSelectors(root, rules, conditions);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should have a unit test too.

@vceder
Copy link

vceder commented Aug 15, 2025

Hi @askoufis, I'm helping luciano with this PR and I've added the tests you asked about and taken a look through the rest, see that we've gotten out of sync with main so will rebase put please take a look at your convince 🙂

@vceder vceder force-pushed the master branch 3 times, most recently from 49616bc to 1eaa63e Compare August 15, 2025 08:29
@askoufis
Copy link
Contributor

@vceder I'm happy with where this PR is currently, though I can't approve a CI run. I think @lfantone might have to enable that in their fork.

@larrifax
Copy link

larrifax commented Nov 6, 2025

@lfantone, @vceder what's the status of this? Looks like the PR needs a rebase & then a CI run..

Looking forward to this feature 👍

@askoufis
Copy link
Contributor

askoufis commented Dec 7, 2025

@lfantone I'm keen to get this PR ready for release if you've got some time. I think you need to change some permissions on your fork in order for me to run CI. Assuming CI passes I'd be happy to merge.

@lfantone
Copy link
Contributor Author

lfantone commented Dec 8, 2025

There we go! I enable Actions in the fork and sync it with upstream.

🙏 Sorry for the long waiting

@askoufis
Copy link
Contributor

@lfantone Could I have permission to push to master of your fork? I've fixed a bug and would like to push a commit but can't.

Alternatively you can apply this patch with git apply 0003-Fix-incorrect-starting-style-serialization.patch.

0003-Fix-incorrect-starting-style-serialization.patch

@lfantone
Copy link
Contributor Author

lfantone commented Dec 14, 2025

@askoufis Yes! Added you as a collaborator in the repo and also apply the given patch

lfantone and others added 3 commits December 14, 2025 15:29
--co-authored-by: Viktor Ceder <viktor.ceder@sas.se>
--co-authored-by: Luciano Fantone <luciano.alvarezfantone@sas.se>
…ests

--co-authored-by: Adam Skoufis <askoufis@users.noreply.github.com>
Comment on lines +2839 to +2840
// BUG: This is a long-standing bug with all at-rules, not just starting-style. This should result
// in a runtime error as well as a type error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated bug I found while fixing a bug in this PR. I'll raise a separate issue for it as I don't want it to block this PR.

@askoufis
Copy link
Contributor

@lfantone Thanks for all your help on this.

@askoufis askoufis merged commit 8b49b35 into vanilla-extract-css:master Dec 15, 2025
10 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.

Support @starting-style

6 participants