compiled icon indicating copy to clipboard operation
compiled copied to clipboard

Expand additional shorthands

Open pancaspe87 opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. At current not all the available CSS shorthands get expanded, eg border: 1px solid black; doesn't get expanded into individual properties.

Describe the solution you'd like We need to add extra logic in https://github.com/atlassian-labs/compiled/tree/master/packages/css/src/plugins/expand-shorthands to support the remaining shorthands

pancaspe87 avatar Aug 10 '21 23:08 pancaspe87

For some context for shorthands it was a tradeoff of how commonly the property is expanded through to how explosive the resulting expansion would be.

Borders are a bit nefarious because they expand to quite a lot of properties, so the decision that was made initially was to ignore them for now.

itsdouges avatar Oct 02 '21 00:10 itsdouges

It seems that having shorthands may not produced the expected output for nested selectors when stylesheet extraction is enabled.

Given

const nestedSelectors = css`
  .intro {
    .intro-heading {
        .intro-logo {
          background: url("https://images.unsplash.com/photo-1593558159516-d0be2a960c52?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8aWNlY3JlYW18ZW58MHx8MHx8&w=1000&q=80") left top no-repeat;
          background-size: 100%;
        }
    }
}`;

Stylesheet extraction will generate

._1b3x1osq .intro .intro-heading .intro-logo{background-size:100%}
._bkmu74eu .intro .intro-heading .intro-logo{background:url("https://images.unsplash.com/photo-1593558159516-d0be2a960c52?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8aWNlY3JlYW18ZW58MHx8MHx8&w=1000&q=80") left top no-repeat}

Resulting in background-size:100% not being applied as it gets overridden by the shorthand and it fallbacks to initial

Workaround break the background shorthand into atomic declarations

Solution

  1. Consider expanding all shorthands OR
  2. Preserve order of CSS declarations. Stylesheet extraction should generate instead
._bkmu74eu .intro .intro-heading .intro-logo{background:url("https://images.unsplash.com/photo-1593558159516-d0be2a960c52?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8aWNlY3JlYW18ZW58MHx8MHx8&w=1000&q=80") left top no-repeat}
._1b3x1osq .intro .intro-heading .intro-logo{background-size:100%}

image

cc @JakeLane

pancaspe87 avatar Jun 02 '22 06:06 pancaspe87