atlassian-labs / compiled

A familiar and performant compile time CSS-in-JS library for React.
https://compiledcssinjs.com
Apache License 2.0
1.98k stars 68 forks source link

Option to increase specificity of generated styles to enable XCSSProp migration #1608

Closed itsdouges closed 8 months ago

itsdouges commented 8 months ago

This pull request introduces a new option to Compiled for increasing the specificity of all styles generated by Compiled, without changing the class name. This enables Compiled to remain deterministic when you have styles built from two or more sources that may or may not have increased specificity turned on.

We're going to be using this for migration to XCSSProp where the platform components haven't yet been migrated to Compiled (away from Emotion). We need to ensure that styles passed through XCSSProp win over Emotion styles in a deterministic way. This was chosen over other solutions such as prepending Emotion styles to the head instead of appending as the unknown of legacy styles in Jira and beyond being unintentionally affected.

To enable set increaseSpecificity to true in your Compiled config:

+increaseSpecificity: true

TODO

changeset-bot[bot] commented 8 months ago

🦋 Changeset detected

Latest commit: 5c1b61bd3d5109c7c20d1a1669f0097cdb1dcad4

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

This PR includes changesets to release 2 packages | Name | Type | | ---------------------- | ----- | | @compiled/babel-plugin | Patch | | @compiled/css | 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

dddlr commented 8 months ago

LGTM assuming that above comments are addressed 👍

itsdouges commented 8 months ago

Okay I've pushed up an improved implementation LMK what folks think.

itsdouges commented 8 months ago

Reminder for myself: make sure this doesn't affect classes that aren't defined by Compiled, just in case.