glamor: CSS rule ordering can break mixed usage of shorthand and non shorthand properties

I’m having hard time reproducing this but it seems that this does not produce predictable results.

Consider following base styles:

const noPadding = css({padding: 0});
const leftPadding = css({paddingLeft: 100});

When combined like:

const combined = css(leftPadding, noPadding);

I would expect that following css would be generated:

.css-12345 {
    padding-left: 100px;
    padding: 0px;
}

but it seems that sometimes this is generated:

.css-12345 {
    padding: 0px;
    padding-left: 100px;
}

Which will results in different layout. I suspect that this is because glamor relies on object key ordering which is not guaranteed in Javascript really. But glamor has the ordering information from the css(leftPadding, noPadding) call so it should be possible enforce the order with glamor.

Has this been already thought out in glamor or do I just have bug in my code? 😃

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 32 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This is also affects border-top-color (and related directions). Example here: https://codesandbox.io/s/qY3G75453

I think the problem arises from mixed usage of the “shorthand” and “extended” version of padding. We had several bugs related to this fact with margin, padding and so on. glamor merges two rules by object assignment for simple properties, so only two identical keys will be merged properly.

Maybe glamor should be more optioniated about what key is merged cc @donaldpipowitch, @ChristopherBiscardi.

In the meantime you can use padding-left, padding-right, padding-top, padding-bottom. This had solved the issue for us 😃