-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 CSSTree for style transformations (new) #21936
Conversation
903d14a
to
dd91ca2
Compare
@youknowriad, @noahtallen: OK, PR is ready. The original structure is preserved. |
|
||
return raw; | ||
} | ||
import { URL } from 'whatwg-url'; |
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.
I know we've gone back and forth about this kind of module and we have a @wordpress/url package. @aduth is this correct, should we replace with our own module instead?
packages/block-editor/src/utils/transform-styles/transforms/test/url-rewrite.js
Outdated
Show resolved
Hide resolved
Can we get a quick sanity checks from theme authors here @kjellr @jasmussen to ensure the editor styles are still working as intended in the editor since this is a big rewrite. @strarsis did you check if there's any performance impact here (initial loading) good or bad? ( |
…` when rewriting URLs.
@youknowriad: Hm, the
The |
Hello! Thanks for the PR and thanks for the ping. I'm usually able to check out branches in forks using this process:
However I'm doing something wrong, as I'm not able to check out and compile this branch, sorry about that. Let me know if you spot my error. To respond at a more high level though, I'm afraid I wasn't familiar with CSStree — what feedback are you looking for? Should the block editor and editor styles ideally look visually unchanged before and after this PR? Or does it change anything with regards to how editor styles are authored? What would be the impact if/when the block editor lands in an iframe and the DOM continues to be lightened until at one point it may be mostly identical to the frontend? |
@jasmussen: An iframe-based approach to style namespacing hasn't been implemented yet. Concerning your branch checkout: I am not sure what went wrong in your case. I use WSL, maybe the line endings accidentally were changed? |
Thanks for taking the time, and thanks again for the PR. I'm not sure why the branch checkout didn't work, but it seems to me like the best way to test this PR is to verify current editor styles look mostly (exactly?) the same before and after this branch, correct? As far as iframes go, while it still might be a ways out, it also might be closer than we think. While it's important that the idea of the iframe PR landing should not stop forward momentum — it might not land, after all — it also seems prudent to think of the iframe as a serious possibility, and avoid painting ourselves into a corner if we can. But it sounds like you're saying making this work with an iframed editor should not be a big refactor? |
I think we should be prudent about the iframe, even if we merge it at first, the PR there showed that we can't get rid of the non-iframed version quickly since the iframe version breaks blocks that rely on the global "window/document" object. That said, If ever we go full iframe, this PR and the whole editor styles normalization won't be needed anymore (so just remove the code). I think this PR is a good PR code wise, avoid the bundled dependency and use a more maintained library. I'd like to check these:
|
@youknowriad: How can this be better tested? I also have issues getting the performance test running, even on master. But I use WSL 1 on Windows, there may be subtle differences. |
Yeah, can't speak about Windows, but once the theme styles are validated properly, I'll help with the performance test. |
@youknowriad: Ideally there should be some theme styles that can be tested against. I could put in all the WordPress core theme styles (minified) like TwentyTwenty. |
I couldn't get the tests running on macos either. Same error as you but it used to work a few months back. |
@oxyc: I managed to get it running. You have to invoke some scripts first and then run puppeteer in headless mode with some extra options. Add fields to puppeteer launch options: module.exports = {
launch: {
devtools: process.env.PUPPETEER_DEVTOOLS === 'true',
headless: process.env.PUPPETEER_HEADLESS !== 'false',
slowMo: parseInt( process.env.PUPPETEER_SLOWMO, 10 ) || 0,
args: [
"--disable-gpu",
"--renderer",
"--no-sandbox",
"--no-service-autorun",
"--no-experiments",
"--no-default-browser-check",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-zygote",
"--single-process",
"--disable-extensions",
],
},
}; Then run the performance test: However, while the performance test runs now on master, it fails with:
( Also, the e2e/performance tests are currently broken in master because of recent changes in inserter search input markup, see #22045. |
I just tried to test this again but This time:
and
Trying to run the tests by mimicking what travis does (on macos):
|
@oxyc: Hm, this error stems from puppeteer/chromium automated testing, when a node can't be found for a selector. But this is on the DOM itself, no CSS involved. The error will also cause the rest of the code failing to load, hence the wp related error afterwards. I think these are issues with the test and changed DOM structure - or a build script that hadn't run and updated the (committed) build artifacts that are used in the automated testing. |
@oxyc The error you're having is because you're not loading the e2e test plugin on your environment (they are in |
also right now on master you can do this to compare two branches |
Sorry for letting this PR stale, I'm still interested in landing this, do you think you can rebase it again? |
@youknowriad: Sure! 🐱 |
…css-tree-transform-styles-2
* WordPress dependencies | ||
*/ | ||
import { compose } from '@wordpress/compose'; | ||
import { map, compose } from 'lodash'; |
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.
I had an error here when testing. "compose" is on @wordpress/element
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.
After fixing the compose error, I tried this PR and it seems the styles are not applied properly. I can tell because the styles of the buttons in 2019, for instance, are not correct (they should be blue and not that rounded)
} | ||
|
||
return css; | ||
return traverse( css, compose( transforms ) ); |
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.
This shouldn't use compose since the result of the second transform gets called with the result of the first (undefined), it should just be fed the original arguments, eg:
return traverse( css, over( transforms ) );
But that would change the old traverse
api.
With the above fix I'm currently getting:
But I guess shouldnt actually have affected the results since they already ran? Might be worth checking again once master is running the tests correctly. If that's true, the initial performance test for Loading time:
|
I am sorry that I hadn't really responded yet, I am very busy right now. |
Found the bug. Before: .editor-styles-wrapper .wp-block-button:not(.is-style-outline) .wp-block-button__link After .editor-styles-wrapper .wp-block-button:not(.editor-styles-wrapper .is-style-outline) .wp-block-button__link |
Here's a fix for the above bug: oxyc@6b746cb And here's a diff of twentyninenteens styles before and after (looks correct) https://gist.github.com/oxyc/479a82cda75d92d0f30ba770c8fbc60f#file-after-patch |
Tested it with own theme where I first encountered #16408 and found another bug: @-webkit-keyframes background-zoom-sm {
- 0% {
+ .editor-styles-wrapper 0% { Fix: oxyc@1c1590b So with the following fixes and a fix for the merge artifacts I'd call the styles verified: |
@oxyc: Awesome, thanks! I got very little time currently, it is nice that you further looked into it. |
@youknowriad, @oxyc, @noahtallen: Superseded by new PR on top of latest upstream master: #25514 |
Description
This PR adds the CSSTree parser for wrapping the theme styles into a styles wrapper.
How has this been tested?
I tested this on my local WordPress site.
Types of changes
(PoCs here: https://codepen.io/strarsis/pen/RwWRqZv and also https://codesandbox.io/s/busy-williamson-r1frp). (Not implemented with this PR, but
CSSTree
adds the foundation for it).Checklist: