Skip to content
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

feat: add support for @starting-style at-rule #1786

Merged

Conversation

michaelabrahamian
Copy link
Collaborator

@michaelabrahamian michaelabrahamian commented Jan 23, 2025

What is this change?

Adding support for the @starting-style at-rule.

Why are we making this change?

So it can be used in animations! Compiled currently throws an exception as it isn't aware of the property.

How are we making this change?


PR checklist

Don't delete me!

I have...

  • Updated or added applicable tests
  • Updated the documentation in website/ - N/A
  • Added a changeset (if making any changes that affect Compiled's behaviour)

TODO:

  • confirm about adding csstype dependency
  • confirm what's going on with the failing test

Copy link

changeset-bot bot commented Jan 23, 2025

🦋 Changeset detected

Latest commit: 21413e5

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

This PR includes changesets to release 6 packages
Name Type
@compiled/babel-plugin Minor
@compiled/css Minor
@compiled/parcel-transformer Patch
@compiled/webpack-loader Patch
@compiled/babel-plugin-strip-runtime Minor
@compiled/parcel-optimizer 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

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for compiled-css-in-js ready!

Name Link
🔨 Latest commit 21413e5
🔍 Latest deploy log https://app.netlify.com/sites/compiled-css-in-js/deploys/679813f1190ba600089bea60
😎 Deploy Preview https://deploy-preview-1786--compiled-css-in-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator Author

@michaelabrahamian michaelabrahamian Jan 23, 2025

Choose a reason for hiding this comment

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

context: mentioned in the PR description, but will repeat here:

The csstype dependency needed to be added so we could satisfy the Record<AtRules, boolean> type here.

expect(actual).toIncludeMultiple([
'._syaz5scu{color:red}',
// TODO: work out why this is failing. The below line is actually being output as '@starting-style color: blue{}'
'@starting-style {._syaz5scu{color:blue}}',
Copy link
Collaborator Author

@michaelabrahamian michaelabrahamian Jan 23, 2025

Choose a reason for hiding this comment

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

question: this assertion isn't working out as I'd expect... Any ideas what I'm doing wrong? Is the input style syntax not valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interestingly, if I change the input to nest another property under @starting-style, e.g.:

const styles = cssMap({
  success: {
    color: 'red',
    '@starting-style': {
      div: {
        color: 'blue',
      }
    },
  },
});

It outputs this:

@starting-style div{._1gzq13q2{color:blue}}

Which makes me think the plugin is doing something wrong? It should be this:

@starting-style { div{._1gzq13q2{color:blue}} }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To sanity check, I tried @font-face, which is an at-rule with a similar syntax to @starting-style:

const styles = cssMap({
  success: {
    color: 'red',
    '@font-face': {
      fontFamily: 'Trickster',
    },
  },
});

This outputs:

@font-face font-family: Trickster

Which seems like the same problem.

The @media test seems to work around this through nesting:

const styles = cssMap({
  success: {
    color: 'red',
    '@media': {
      'screen and (min-width: 500px)': {
        color: 'blue',
      },
    },
  },
});

Outputs:

@media screen and (min-width:500px){._1qhm13q2{color:blue}}

Which is valid syntax for @media... But @starting-style (and @font-face) don't accept args, so doesn't make sense here.

@michaelabrahamian michaelabrahamian self-assigned this Jan 23, 2025
@@ -20,7 +20,9 @@ const atRules: Record<AtRules, boolean> = {
'@namespace': true,
'@page': true,
'@property': true,
'@scope': true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

context: @scope was also added as it is a member of the AtRules type in the updated version of csstype. Needed to satisfy the Record type.

@michaelabrahamian michaelabrahamian force-pushed the BLU-6338-add-support-for-starting-style-at-rule branch from 259ab67 to 21413e5 Compare January 27, 2025 23:17
@michaelabrahamian michaelabrahamian marked this pull request as ready for review January 27, 2025 23:17
@michaelabrahamian michaelabrahamian merged commit 0f64c39 into master Jan 28, 2025
13 of 15 checks passed
@michaelabrahamian michaelabrahamian deleted the BLU-6338-add-support-for-starting-style-at-rule branch January 28, 2025 00:33
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