-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Use PostCSS + PostCSS plugins for style transformation #49521
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @strarsis! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Well, tests do not pass yet, some modifications have to be made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gutenberg isn't building here, I'm not sure if I'm missing something:
ERROR in ./node_modules/postcss-editor-styles/node_modules/postcss/lib/input.js 6:35-50
Module not found: Error: Can't resolve 'path' in '/Users/zaguini/Development/gutenberg/node_modules/postcss-editor-styles/node_modules/postcss/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
The following diff fixes this problem:
diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js
index 30f73a82fa..815dbf3a82 100644
--- a/tools/webpack/packages.js
+++ b/tools/webpack/packages.js
@@ -120,6 +120,11 @@ const vendorsCopyConfig = Object.entries( vendors ).flatMap(
);
module.exports = {
...baseConfig,
+ resolve: {
+ fallback: {
+ path: false,
+ },
+ },
name: 'packages',
entry: gutenbergPackages.reduce( ( memo, packageName ) => {
return {
wrap( { scopeTo: wrapperClassName } ), | ||
rebaseUrl( { rootUrl: baseURL } ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! It's very smart to use existing transformers instead of building in-house ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though the rebaseUrl
had to be created by me, as there are no plugins yet that do exactly that.
Is there a way to expose a CSS traverse function? I think it's possible with |
return postcss( [ | ||
wrap( { scopeTo: wrapperClassName } ), | ||
rebaseUrl( { rootUrl: baseURL } ), | ||
] ).process( css, {} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.process
returns a LazyResult
(Promise). Reference: https://postcss.org/api/#processor-process
Well, this is unfortunate... We need to make this sync And this is how we can make it a sync operation: postcss/postcss#1328 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the sync variant should also work.
Yes,
There is an alternative PostCSS plugin that has the required features but should be much more lightweight: |
So I run into some roadblocks while making this PR mergeable: Using the last commit that passes the CI tests (69a1573), a few tests fail on my workstation.
A few tests fail:
The test hangs at this point. These are the
Am I missing a |
Wow, weird error indeed @strarsis. @gziolo @youknowriad do you have any idea on how to fix this problem? @strarsis I also see there's a conflict now with |
@zaguiini: I first tried to let the tests of the PR pass, which did not work fully. Edit: The tests finally finished:
Three and a half hours is a bit excessive... But the 19 failed tests are the main issue. Addendum: After resetting everything the tests now ran for 5 minutes, which is much better. Though some are still failing. |
Alright, apparently the tests ran at commit are not the same as the one by the |
Hm, some checks fail. I have to find out, why those failed. |
I would really like to get this passing and merged. Why does that E2E test fail, is this actually caused by the changes in this PR? |
@gziolo @jsnajdr @youknowriad could you please help @strarsis here? |
@strarsis Yes, there are React errors reporting that a
The Generally, the idea of this PR is interesting -- bundling and using the |
@jsnajdr: Thanks for the pointer! |
Hi @starsis 👋 As the last step, can you please rebase the PR onto the latest |
@strarsis do you have time to work on this issue? If not, I'd appreciate writing permissions to your repo so that I could push changes too. |
@zaguiini: Sure! Sadly I had been too busy. I sent you an invitation. |
a9a361d
to
dddafc1
Compare
@strarsis @jsnajdr how would you test it? Should we add some of the transformer tests that were removed (please provide examples) and adapt to the I also noticed that some PHP tests are failing. Surely, it's flakiness, as the PR doesn't touch PHP files. But it'd be good to confirm. |
26e0f88
to
05c3606
Compare
Congratulations on your first merged pull request, @strarsis! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
@strarsis This PR is finally merged 🎉 🎉 Could you please close the related issues and PRs and communicate the folks that this is finally over? Thanks! |
@zaguiini: Done! I also added the note to issues/PRs that are related to style isolation and discussed issues with the CSS parsing. |
What?
This PR uses PostCSS and PostCSS plugins for style transformations.
Why?
The internal CSS parser has compatibility and stability issues, as it is not a dedicated, separate library.
How?
Using PostCSS ensures that a dedicated and well-supported library is used.
Testing Instructions
note that the editor styles are correctly post-processed and applied, resulting in correctly wrapped selectors and rewritten URLs.
Related PR: #49483