Emotion: Upgrading to Emotion 11 no longer filters out invalid css rules

Created on 8 Dec 2020  路  2Comments  路  Source: emotion-js/emotion

Current behavior:
Previously emotion would filter out invalid css rules e.g. background-color: ${undefined} would return nothing and get filtered out.

To reproduce:
https://codesandbox.io/s/emotion-issue-template-forked-4qi2s

Expected behavior:
invalid rules should be removed/filtered

Environment information:
emotion 11

Additional Notes:
The goal is an elegant solution to conditional css rules. The alternative to not hiding invalid rules is very messy:

h1 {
  ${props => props.color && (
    css`
      color: ${props.color};
  `)}
}
bug needs triage

Most helpful comment

As a workaround object styles can be used: https://codesandbox.io/s/emotion-issue-template-forked-f8fs2?file=/src/index.js

Note to myself: this has changed between Stylis 3 and 4. I'll give this a thought if we should align with the old behavior.

All 2 comments

As a workaround object styles can be used: https://codesandbox.io/s/emotion-issue-template-forked-f8fs2?file=/src/index.js

Note to myself: this has changed between Stylis 3 and 4. I'll give this a thought if we should align with the old behavior.

The PR to stylis that is fixing this has been merged in - hopefully it will get released shortly

Was this page helpful?
0 / 5 - 0 ratings