-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
A race condition issue in postcss-custom-properties
#331
Comments
Thank you for reporting this! I don't think you even need the second async plugin to trigger this. At the moment it only supports reuse of the same instance in series, not in parallel. To use the plugin in parallel you can create multiple instances. |
@romainmenke I added a Root issue and solution section in this issue's description. I tested it in my project and it works. Could you take a look? Also if it is ok I'm glad to create a PR later. |
My current gut feeling is that everything should be moved into Any PR is always welcome! |
@malash this has been released as |
Bug description
Recently I found a race condition issue of
postcss-custom-properties
while using it with other async PostCSS plugins.I cost a lot of time to figure out the root issue and finally I can provide a easy way to reproduce this bug.
Full example repo: https://github.com/malash/postcss-plugins-issue-331
To reproduce this issue you need:
postcss-custom-properties
with another async plugin ( which means the listeners of plugin should return a promise ).I implemented this fake plugin:
postcss-custom-properties
.process
method in parallel. Make sure one CSS contains custom properties and others doesn't.WITH_CUSTOM_PROPERTIES
, thevar(--color)
is not replaced as expected.Root issue and solution
I believe the root cause is this line:
postcss-plugins/plugins/postcss-custom-properties/src/index.ts
Line 51 in e9893a0
The plugin function is initialed only once in the
postcss([pluginFn()])
call. But theprepare
listener runs for each CSS input file. In this plugin, thecustomProperties
should be placed `prepare function.Source CSS
Expected CSS
Actual CSS
Does it happen with
npx @csstools/csstools-cli <plugin-name> minimal-example.css
?No
Debug output
No response
Extra config
No response
What plugin are you experiencing this issue on?
No response
Plugin version
12.1.6
What OS are you experiencing this on?
macOS
Node Version
16.13.0
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: