Skip to content
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

transformStyles not working correctly #16408

Closed
pascalknecht opened this issue Jul 3, 2019 · 7 comments
Closed

transformStyles not working correctly #16408

pascalknecht opened this issue Jul 3, 2019 · 7 comments
Labels
[Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended

Comments

@pascalknecht
Copy link

pascalknecht commented Jul 3, 2019

Describe the bug
When loading custom css via add_editor_styles not every style is applied when any element has an svg background encoded as a data:image/svg.

To reproduce
Steps to reproduce the behavior:

  1. Enter the following code into the console
    wp.editor.transformStyles([{css: ".navbar-light .navbar-toggler-icon {↵background-image: url(\"data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E\")}"}], '.editor-styles-wrapper');

Expected behavior
The styles should be transformed with .editor-styles-wrapper in front.

Additional context

  • Gutenberg 6.0.0
@swissspidy swissspidy added [Package] Editor /packages/editor Needs Testing Needs further testing to be confirmed. labels Jul 3, 2019
@oxyc
Copy link
Member

oxyc commented Aug 22, 2019

I just hit this as well when having having swiper included. It breaks at https://github.com/nolimits4web/swiper/blob/1c4dfa3b08727f7febd9238980d8249d89202702/dist/css/swiper.css#L490

See reworkcss/css#67. I can also confirm this only happens when the css is minified as mentioned here reworkcss/css#67 (comment)

@noisysocks
Copy link
Member

This seems to be working for me. When I paste the snippet into my console I get:

[
	".editor-styles-wrapper .navbar-light .navbar-toggler-icon { background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E"); }"
]

@oxyc
Copy link
Member

oxyc commented Apr 2, 2020

@noisysocks I think the test case was wrong. See the upstream bug report I mentioned in #16408 (comment).

I have a working PR for this #17146

A reproducible test is (notice that the second selector does not become prefixed):

wp.editor.transformStyles([{css: `.foo {background-image: url(\"data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E\")} .bar {background-image: url(\"data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E\")}`}], '.editor-styles-wrapper');

Or simpler:

wp.editor.transformStyles([{css: `.foo {background-image: url(\"data:image/svg+xml;charset=utf8,%3Csvg stroke='rgba(0, 0, 0, 0.5)'%3C/svg%3E\")} .bar {background-image: url(\"data:image/svg+xml;charset=utf8,%3Csvg stroke='rgba(0, 0, 0, 0.5)'%3C/svg%3E\")}`}], '.editor-styles-wrapper');

Even simpler:

wp.editor.transformStyles([{css: `.a { b: url(")"); d: url(";a"); }`}], '.editor-styles-wrapper');

@noisysocks noisysocks reopened this Apr 2, 2020
@noisysocks noisysocks added [Type] Bug An existing feature does not function as intended and removed Needs Testing Needs further testing to be confirmed. labels Apr 2, 2020
@noisysocks
Copy link
Member

Thanks @oxyc—you're totally right and that second example there demonstrates the bug when I run it locally.

@strarsis
Copy link
Contributor

Similar issue: #21569
Relevant PR: #21936

@strarsis
Copy link
Contributor

New editor styles transformation approach using PostCSS is now merged (many thanks @zaguiini)!

@skorasaurus
Copy link
Member

skorasaurus commented Oct 23, 2023

This is now fixed thanks to the work of @zaguiini and @strarsis !

This will be included in gutenberg 17.0; was specifically #49521

before #49521

image

after:
image

@oxyc I've also confirmed that the merged PR fixes your reduced test cases as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants