Skip to content

Add support for @starting-style rules #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lfantone
Copy link

@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.

Copy link

changeset-bot bot commented Apr 6, 2025

🦋 Changeset detected

Latest commit: c392d65

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
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
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
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
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.

@@ -60,3 +60,11 @@ export const styleVariantsCompositionInSelector = styleVariants({
globalStyle(`body ${styleVariantsCompositionInSelector.variant}`, {
fontSize: '24px',
});

// Style with starting-style
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Style with starting-style

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.

'@vanilla-extract/css': minor
---

Add support for `@starting-style` rules
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Add support for `@starting-style` rules
`style`: Add support for `@starting-style` rules
**EXAMPLE USAGE**:
```ts
import { style } from '@vanilla-extact/css';
export const styleWithStartingStyle = style({
backgroundColor: 'black',
'@starting-style': {
backgroundColor: 'white',
},
});
```

@@ -52,12 +52,16 @@ export type MediaQueries<StyleType> = Query<'@media', StyleType>;
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
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 +624 to +626
// Check if there are any nested at-rule keys inside this block.
// The presence of any key starting with '@' indicates nested queries,
// which are not allowed for @starting-style.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just flagging that this is actually valid CSS. @media inside @starting-style is valid (example), but it relies on your browser supporting CSS nesting.

Actually, looking at the CSS output of your implementation, it generates nested CSS (@starting-style inside a selector). However, @starting-style is baseline, and it's newer than CSS nesting, so all browsers that support @starting-style support CSS nesting, so I think this is fine. However, I think for the sake of simplicity, disallowing further nested CSS within @starting-style is the right move for now. We can always remove this restriction in the future if necessary.

Comment on lines +412 to +416
this.transformStartingStyle(
root,
selectorRule!['@starting-style'],
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 transformation inside selectors needs a unit test.

Comment on lines +574 to +578
this.transformStartingStyle(
root,
supportsRule!['@starting-style'],
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 transformation inside @supports needs a unit test.

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.

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
4 participants