emotion: Invalid CSS output from function based dynamic styles
Current behavior:
Using an array of styles leads to invalid CSS properties in the DOM named label, name, and styles.
On the first style passed, the invalid CSS prop label does not appear in the DOM, but for subsequent styles it does. Additionally the first rule in the CSS in each style passed is nested invalidly like so: styles: color: red;

To reproduce:
Can’t reproduce this issue on CodeSandbox - so possibly related to I get this issue whether I use the plugin or not.babel or webpack would be my guess. Does the order of babel plugins matter when including the emotion plugin?
Expected behavior:
No invalid props in the DOM and the first rule is not mangled and ignored.
Environment information:
reactversion:16.9.0emotionversion:10.0.17
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 24 (21 by maintainers)
Just encountered this problem while migrating from v9 to v11. Removing
emotionfrom babel plugins fixed it for me as I already have@emotion/babel-preset-css-propin babel presets.Unfortunately, nothing comes to my mind as to what we could do to warn about smth like this.
Indeed it looks like a
styled-componentsbabel plugin was in a nested.babelrcand it was passingpropsto my style partials. Pretty crazy side effect.So the only real bug here will be addressed by #1553
I don’t suppose there’s any easy way to detect that the
styled-componentsplugin is in use fromemotion’s side? It’s not really within the scope of the project, but if it would be possible and easy, perhaps it would be worth it in the interest of preventing future issues like this from gunking up the issue tracker.Thanks for your patience and assistance @Andarist.
Nope, we don’t depend anyhow on styled-components.
Maybe it’s somehow inserted by some babel plugin? Just a wild guess.
Put a debugger in there and check out the stack trace to see what gives you that props argument.
Regarding keyframes stuff - for now you should wrap it with
css. We are going to either allow interpolating keyframes output into plain strings or introduce a dev warning about misusing it. See https://github.com/emotion-js/emotion/pull/1553 .Interpolating into strings:
and into tagged template calls
is a different thing, although they look pretty much similar. With tagged templates we receive what you actually put in there, but with a plain string the interpolated value gets stringified by JavaScript.
Thanks for the sandbox - gonna investigate this some time later.
Not sure if this helps… but… i have seen this happen when you don’t close off the css selectors correctly. I have had a few examples of this happen over time and i have to really look deep into the css and see if i have not forgotten to add a semi-colon at the end of the css selectors. Otherwise i get the name issue as you are explaining.
for example:
would output the css concatenated. But this would be ok…
can you provide a codesandbox for your last case?
If you can’t repro this on codesandbox a regular repository is acceptable as repro too - we just recommend codesandbox as it’s easier to setup.