Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXAMPLE: Sort shorthand vs. longhand declarations — breaking change behind config #1700

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kylorhall-atlassian
Copy link
Collaborator

@kylorhall-atlassian kylorhall-atlassian commented Jul 22, 2024

What is this change?

Adds sorting of shorthand vs. longhand to ensure longhand deterministically will override shorthand.

⚠️ This could result in regressions as this will no longer work, so it's behind config, but this may mean this change should never go through (if we added border to this sorting):

const styles = css({ borderTop: '1px solid blue' });
const noBorderStyles = css({ border: 'none' });

export default ({ noBorder }) => <div
  css={[styles, noBorder && noBorderStyles]}
/>

Why are we making this change?

This is because quite commonly this code may be applied in either direction meaning sometimes font-weight: bold is applied and sometimes it's not, depending on the order that the stylesheet was generated in.

const styles = css({ font: '12px / 24px' });
const boldStyles = css({ fontWeight: 'bold' });

export default ({ isBold }) => <div
  css={[styles, isBold && boldStyles]}
/>

Example in a Storybook:
Screenshot 2024-07-22 at 3 47 41 PM

How are we making this change?

Where we already sort atomic styles, we now sort shorthand vs. longhand in that same area.


PR checklist

  • Validate this works consistently as it's unclear if this sortAtomicStyleSheet iterates over all declarations or just one by one
  • Added an applicable test suite
  • Expand the list of shorthand properties, right now this is just outline and font, there are many more!
  • Investigate if there's further tests to update
  • Update the documentation in website/ with this new config

Copy link

changeset-bot bot commented Jul 22, 2024

⚠️ No Changeset found

Latest commit: 89df158

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Jul 22, 2024

Deploy Preview for compiled-css-in-js canceled.

Name Link
🔨 Latest commit 89df158
🔍 Latest deploy log https://app.netlify.com/sites/compiled-css-in-js/deploys/66d69daab2750900080884e8

…rting as well.

Concerns:
 - Runtime sorting does not work properly as we'd also need per-bucket nested sorting where `@media, :focus, border` needs to be sorted.
 - `shorthandFor` needs 40 more shorthand properties defined…
]}
</Style>
);

// WARNING: This is wrong, the `focus` border properties are different than without focus, borders would be indeterministic.
Copy link
Collaborator Author

@kylorhall-atlassian kylorhall-atlassian Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is required, all "bucket sorting" needs to be drastically rewritten to be nested.

Right now it's flat:

.abc { border: none }
.abc:link { border: none }
.abc:visited { border: none }
/* … */
.abc:active { border: none }
@media (/* … */) { .abc { border: none } }

But this doesn't support @media (…) being sorted internally or .abc:focus { … } being sorted against each other.

This would need deeper nested bucketing:

.abc { border: none }
.abc{ border-top: none }
.abc:link { border: none }
.abc:link { border-top: none }
@media (/* … */) {
  .abc { border: none }
  .abc { border-top: none }
  .abc:active { border: none }
  .abc:active { border-top: none }
}

And I'm not exactly sure if that's even feasible for @media queries either…

…uents.

This no longer sorts `border-top` vs. `border-block-start` as they are siblings, not a sibling of a constituent…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant