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

Keyframes cannot be declared in template literals #1673

Open
miloofcroton opened this issue May 15, 2024 · 2 comments
Open

Keyframes cannot be declared in template literals #1673

miloofcroton opened this issue May 15, 2024 · 2 comments

Comments

@miloofcroton
Copy link

miloofcroton commented May 15, 2024

Describe the bug
Keyframes cannot be declared in template literals (ie css'' or keyframes''), although they can referenced in template literals.

To Reproduce
Steps to reproduce the behavior:

This fails:

const myRotate = keyframes`
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
`;

But this succeeds:

const myRotate = keyframes({
  from: {
    transform: 'rotate(0deg)',
  },
  to: {
    transform: 'rotate(360deg)',
  }
})

For this reference:

const Keyframe = () => (
  <div css={`
      animation: ${myRotate} 2s linear infinite;
  `}>
    TEST
  </div>
)

Error info:

SyntaxError: This AssignmentExpression was unable to have its styles extracted — try to define them statically using Compiled APIs instead. (This is an error on an internal node. Probably an internal error.)
    at Array.forEach (<anonymous>)
    at Array.reduce (<anonymous>)

Expected behavior
I expect to be able to write keyframes using template literals as explained in the documentation: https://compiledcssinjs.com/docs/api-keyframes

Screenshots

Error screenshot:

Screenshot 2024-05-15 at 17 03 37

Dependencies:

    "@compiled/react": "^0.17.1",
    "next": "14.2.3",
    "react": "^18",
    "react-dom": "^18"

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Firefox v125

Additional context
I'm using the babel plugin "@compiled/babel-plugin" with the /** @jsxImportSource @compiled/react */ at the top of every file.

I'm new to the library, so there is always the chance that I'm doing something wrong.

@miloofcroton
Copy link
Author

miloofcroton commented May 16, 2024

Looks like I'm having an almost identical issue with declaring css tagged template literals outside of the components, so it's not specifically an issue with the keyframes function. Is this some sort of clash between Compiled, Next, and/or Babel?

I'm able to remove the css, making it a simple template literal, and the code compiles correctly. However, I'm not able to do the same thing with removing the keyframe tag and have that template literal work. So, I guess they appear to be the same, but the workaround would have to be slightly different.

@miloofcroton
Copy link
Author

Ok, I figured out a solution: I was using only the babel config option. When I undid the babel config changes and instead used the webpack config changes, everything was resolved. I am now able to use css and keyframe tagged template literals. Maybe this edge case should be mentioned in docs?

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

No branches or pull requests

1 participant