-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix: use onceexit
(instead of once
) which runs after all children are processed
#41
base: master
Are you sure you want to change the base?
Conversation
e99b310
to
53dbff6
Compare
@alexander-akait: Any thoughts? |
Sorry, in this case we will break other scenarios, it is breaking change, css modules should be always last |
Can you describe these other scenarios that would break? Just to elaborate on the motivation for this change: there are plugins like
into:
Because this plugin currently runs first, not last, it parses and exports the selector name |
|
That's only if This is what postcss 8 recommends plugins do if possible, instead of running in module.exports = {
postcssPlugin: 'postcss-dark-theme-class',
- Once (root) {
- root.walkAtRules(atRule => {
- // Slow
- })
- }
+ AtRule (atRule) {
+ // Faster
+ }
}
module.exports.postcss = true |
But it should work too, there are a lot of other plugins and css-loader rely on our behavior, I am really can't change it, it will be big breaching change and require rewrite many things |
No, My 2 cents is that while this could potentially be a breaking change, this should have been part of the 3.0 release to properly support newer postcss 8.x plugins which have been migrated away from running in the Out of curiosity, I checked out |
For example, if you do
But since postcss-each uses a child hook (AtRule), which is what postcss recommends you do for new and migrated plugins, the order is the following:
The more appropriate handler for all plugins that need to walk the entire tree once like this plugin does, would be to use OnceExit beginning with postcss 8:
|
In this case cssnano will be broken, because they use |
Agreed it would be a breaking change for someone who is relying on this implementation detail. However, there is a simple fix available in this case -- just switch the plugin order to make it explicit you want either postcss-module-scope or cssnano to run first. For someone who wants to use postss-each (or any plugin that doesn't run on |
@ai: If you have any thoughts here, it would be appreciated. |
Changing It is better to rewrite plugin to |
@ai: Let's say this plugin does use |
Why we can’t change |
@ai Because we need collect all of them, I have talked about this potential issue earlier, the simplest solution - adding |
Why do you need to collect all selectors before changing any selector? |
@ai For collection purposes, we need collect all |
Why we can't do it? |
Can you show how I can do it? We need collect all |
|
It is not working, because we need collect all |
See: https://postcss.org/api/#plugin-onceexit
This gives other postcss plugins (like postcss-each) a chance to run first and modify the AST.