8000 [postcss-plugin] Add @layer and polyfill support via @csstools/postcss-cascade-layers by jeongminsang · Pull Request #1072 · facebook/stylex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[postcss-plugin] Add @layer and polyfill support via @csstools/postcss-cascade-layers #1072

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jeongminsang
Copy link
@jeongminsang jeongminsang commented May 21, 2025

What changed / motivation ?

This update refactors the useCSSLayers option to streamline the implementation of CSS layer polyfilling. We're replacing our custom, internally handled polyfill with the robust and well-maintained @csstools/postcss-cascade-layers library. This ensures a more compliant and robust solution for handling CSS layer specificity.

Linked PR/Issues

Fixes #1062

Additional Context

useCSSLayers Option Refactoring

The previously self-implemented polyfill logic has been removed:

// babal-plugin/src/index.js
if (!useLayers) {
	ltrRule = addSpecificityLevel(ltrRule, index);
	rtlRule = rtlRule && addSpecificityLevel(rtlRule, index);
}

The polyfill functionality is now powered by @csstools/postcss-cascade-layers, ensuring a more robust and compliant solution:

// babel-plugin/src/index.js
async function transformCollectedCSS(collectedCSS: string): Promise<string> {
  return (await postcss([cascadeLayers()]).process(collectedCSS)).css;
}

@facebook-github-bot
Copy link

Hi @jeongminsang!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 21, 2025
Copy link
Contributor
@necolas necolas left a comment

Choose a reason for hiding this comment

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

Thanks for giving this a try.

The layers polyfill should be part of the babel-plugin processStylexRules method. The unit tests for that API should also be updated to snapshot the output from the 3 different options. The other packages like the CLI and postcss-plugin can then call into processStylexRules and pass an options object instead of the current boolean.

@jeongminsang
Copy link
Author

@necolas,
I'm considering implementing the polyfill for @csstools/postcss-cascade-layers within the processStylexRules method, as per your review. However, this change would require processStylexRules to become an async function, which could lead to significant breaking changes across the codebase. Are these extensive changes what you intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[babel-plugin] Better options for processStylexRules
3 participants
0