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

"kebab" method improperly used on style value in data URL #206

Closed
TheBosZ opened this issue Aug 29, 2018 · 2 comments · May be fixed by donavon/react-use#1
Closed

"kebab" method improperly used on style value in data URL #206

TheBosZ opened this issue Aug 29, 2018 · 2 comments · May be fixed by donavon/react-use#1

Comments

@TheBosZ
Copy link
Contributor

TheBosZ commented Aug 29, 2018

This is related to #203, but slightly different.

We stopped using the "important" addon because we finally excised all SASS files, but this is causing issues.

We have a style definition of this:

{
  'background-image': 'url("data:image/svg+xml;utf8,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' width=\'48\' height=\'36\' viewBox=\'0 0 48 36\' fill=\'rgb(28,28,28)\'%3E%3Crect x=\'16\' y=\'12\' width=\'16\' height=\'2\' /%3E%3Crect x=\'16\' y=\'17\' width=\'16\' height=\'2\' /%3E%3Crect x=\'16\' y=\'22\' width=\'16\' height=\'2\' /%3E%3C/svg>")',
}

It generates the following style:

background-image:url("data:image/svg+xml;utf8,%3-csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='48' height='36' viewBox='0 0 48 36' fill='rgb(28,28,28)'%3E%3Crect x='16' y='12' width='16' height='2' /%3E%3Crect x='16' y='17' width='16' height='2' /%3E%3Crect x='16' y='22' width='16' height='2' /%3E%3C/svg>");

Notice how the characters "utf8,%3Csvg" got converted to "utf8,%3-csvg". That breaks the XML and causes the rule to be dropped by the browser.

The correct rule is:

background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='48' height='36' viewBox='0 0 48 36' fill='rgb(28,28,28)'%3E%3Crect x='16' y='12' width='16' height='2' /%3E%3Crect x='16' y='17' width='16' height='2' /%3E%3Crect x='16' y='22' width='16' height='2' /%3E%3C/svg>");

Note: I'm assuming that kebab is to blame here, but I don't really know. It's quite possible that kebab shouldn't be run on url() values.

@TheBosZ
Copy link
Contributor Author

TheBosZ commented Sep 13, 2018

Turns out it's the prefixer plugin. I've submitted #208 to fix it.

streamich pushed a commit that referenced this issue Sep 18, 2018
* Properly kebab ms prefix

Also added test

* Reworked prefixer to be smarter

Instead of blindly splitting on ';', we can instead return an object from .prefixer() and then use that to build the string.

I think it's cleaner this way.

Closes #206
streamich pushed a commit that referenced this issue Sep 18, 2018
# [3.4.0](v3.3.0...v3.4.0) (2018-09-18)

### Features

* better prefixing ([e5e83c4](e5e83c4)), closes [#206](#206)
@streamich
Copy link
Owner

🎉 This issue has been resolved in version 3.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants