-
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
Fix or replace CSS Parser that transforms editor styles #40444
Comments
Possible workaroundA big chunk of the issues seem to stem from the fact that nested So for example, this line isn't properly parsed.
but is if you are writing it like this:
|
Thanks for raising this issue. For the longest time we've not used the official The issue we keep running into, is that unlike the browser, the editor style parser used in here does not fail gracefully but instead fails completely when there are any issues in the CSS input. This would be fine if the parser were perfect and had no issues with perfectly valid syntax. But with these issues it causes problems. So thanks again for raising this issue and for taking anyone also taking a look at this :) |
If this has bitten you because of PostCSS, you might want to know that if you're using If you detect any issue that can be prevented (or is caused by us) I'd be more than happy to take a look. |
I think this is the place to report issues with the CSS Parser. I noticed that after updating to WP 6.0, during theme development when Gutenberg was loading our unminified main.css stylesheet none of our styles were being applied properly, but it worked fine with the .min.css file. I have isolated the issue. When using an inline svg which has a style attribute, if a semi-colin is included at the end of the attribute, the parser breaks and no styles are loaded. E.g. this breaks and fails to load any CSS:
This works:
So just changing I hope this helps, please let me know if I should report it somewhere else. |
@patrickwc: This sounds like this CSS parser-related issue: #21569 |
The parser seems to error when trying to parse |
I stumbled upon this issue again today... It's so frustrating. Applying CSS rules that are perfectly valid break the block when the page initially loads. Is there any activity here? Any way to help move this forward? |
Thanks, @strarsis! So I'm guessing that the concern is mostly about bundle size increases. Are all functionalities of |
@zaguiini: Yes, cherry-picking and tree-shaking and other optimizations for getting the size down would be great. |
Cool @strarsis, let me know if you need any help. If you don't have the bandwidth to work on it, I'd be happy to take over. |
@zaguiini: Yes! When you could find out how to reduce the bundle size the PR can be finally merged and most if not all parsing issues fixed (it will use a proper, well-tested CSS parser). |
Any movement on this? Currently I'm needing to enqueue a separate stylesheet (see comment) for all my container queries, while also adding my main styles the proper way through add_editor_style so I benefit from the .editor-styles-wrapper scoping class it adds for everything else. Container queries are such a perfect fit for block development since blocks can appear within many width contexts, which media queries can't accommodate since they're just looking at the entire viewport's width. |
I pushed some more commits to the PR. Please check it again: #49521 (comment) |
@tcmulder, @kraftner, @skorasaurus, @Antonio-Laguna, @fabiankaegy, @patrickwc, @wongjn: |
Thanks for the work everyone. Should we close this issue @strarsis |
@youknowriad: This should fix the issues linked above, so IMHO yes, this can be closed for now. |
What problem does this address?
The currently used CSS parser implementation to transform editor styles is fragile and breaks on multiple kinds of perfectly valid CSS.
Since there are currently multiple issues and PRs with varying descriptions that seem to all point back to this very problem I thought I'd summarize and consolidate them here to streamline further steps.
Examples / Other issues
To begin some examples of what we are talking about:
What is your proposed solution?
Earlier attempts
The parsing is currently done here which is an adapted fork of https://github.com/reworkcss/css. It seems though that the upstream package has identified the issue as well but has no fix and isn't actively maintained anyway (the last release being from early 2020)
There has been an attempt to fix it by @oxyc based on the upstream issue:
This got closed in favor of another approach by @strarsis that seemed to be better but then got stalled due to an increase in bundle size
Finally at the end of this PR @strarsis proposed another approach using "native Browser API and a CSS selector parser" that might be a viable middle ground: #25514 (comment)
Next steps
I currently see 3 possible ways to solve this:
Finally there currently is the endeavor to iframe the editor content so the original CSS can be used making the whole transformation including all these issues go away
Since this might still take some time though it might still be a good idea to fix this in the meantime.
What would probably be nice in any case and a good first step is to add some tests covering the above issues since there currently is pretty much no coverage at all for this.
The text was updated successfully, but these errors were encountered: