Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Conversation

jbalsas
Copy link
Member

@jbalsas jbalsas commented Oct 4, 2023

WHY are these changes introduced?

This is a companion PR to Add support for @custom-media for using breakpoints in CSS.

It adds a migration to replace existing usages of polaris scss media queries in admin to the new @custom-media approach.

WHAT is this pull request doing?

Basically, it turns

@use 'global-styles/media-queries';

.Selector {
  max-width: 100px;

  @media #{media-queries.$p-breakpoints-md-down} {
    max-width: 200px;
  }
}

into

@use 'global-styles/media-queries';

.Selector {
  max-width: 100px;

  @media (--p-breakpoints-md-down) {
    max-width: 200px;
  }

Additionally, it removes the jscodeshift preset as per @aaronccasanova and @sam-b-rose comments here

How to 🎩

I think tests should be enough, but here are some things to take into account:

  • It converts both @media and @container since that's the only usage we currently have and not everywhere media queries are allowed
  • Decided not to remove the @use rule to simplify the migration. This can be don by running the remote-unused-at-rule migration later
  • Went with admin- for the rule since it mostly applies to admin codebase, but happy to put under the scss- or syles- umbrellas if we think there's value there
  • Adjusted my previous approach following @aaronccasanova's suggestion here
  • This in itself does not make the system to work, as it needs a combination of plugins to provide proper build and runtime support.

🎩 checklist

@jbalsas jbalsas requested review from a team as code owners October 4, 2023 12:56
@jbalsas jbalsas force-pushed the jbalsas/custom-media-migration branch from 4c61138 to 40ddb37 Compare October 4, 2023 14:01
Copy link
Member

@kyledurand kyledurand left a comment

Choose a reason for hiding this comment

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

🙌

@jbalsas
Copy link
Member Author

jbalsas commented Oct 4, 2023

Results of this migration can be seen in action in shopify/web in https://github.com/Shopify/web/pull/105850

@jbalsas jbalsas changed the title Adds admin migration from sass media-queries to @custom-media [polaris-migrator] Add admin migration from sass media-queries to @custom-media Oct 4, 2023
AtRule(atRule) {
if (atRule.name === 'media' || atRule.name === 'container') {
atRule.params = atRule.params.replace(
/#\{media-queries\.\$(?<breakpoint>[^}]*)}/g,
Copy link
Member

Choose a reason for hiding this comment

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

Can we make the namespace (e.g. media-queries.) a CLI flag? For example, see the tokenize-font migration and associated tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure... do we know of other codebases that would want to apply the migration and use a different namespace?

This was the reason that pushed me to just call this admin- and not make it more generic.

I think constructing the regex out of strings is going to get a bit more hairy than this, but definitely makes sense if we think this can be generalized 🤔

Copy link
Member

Choose a reason for hiding this comment

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

The Polaris migrator is usable by Polaris, Web, 1Ps, and 3Ps. If this migration is admin specific, can you add it to web/tooling/stylelint/rules?

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense... do you have examples of some of those 1Ps I could check?

I think this migration is at the moment a bit specific since it relies on the way previous polaris version were managed which might have taken a different path on different codebases.

I'd like to see if this can be applied to other codebases and how to generalize it if that's the case before making a final call on this.

Copy link
Member

Choose a reason for hiding this comment

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

do you have examples of some of those 1Ps I could check?

https://grokt.shopify.io/results?q=-repo%3AShopify%2Fpolaris+-repo%3AShopify%2Fweb+%5C%24p-breakpoints-

I'd like to see if this can be applied to other codebases and how to generalize it

I think an optional namespace should be sufficient

I think constructing the regex out of strings is going to get a bit more hairy than this

Let me know if you need assistance 👍

Copy link
Contributor

github-actions bot commented Apr 8, 2024

Hi! We noticed there hasn’t been activity on this PR in a while. After 30 days, it will close automatically.

If it’s still relevant, or you have updates, comment and let us know. And don’t worry, you can always re-open later if needed.

@jbalsas
Copy link
Member Author

jbalsas commented Apr 8, 2024

Similar to #10749

Going to close here since we ran this once for web and haven't needed it since. We can always come back and bring this back if needed, but probably better to keep the migrator as lean as we can to avoid bloat.

@jbalsas jbalsas closed this Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants