Closed rbiggs closed 6 years ago
By the way, here's a Codepen with xlink:href
working with h
: https://codepen.io/rbiggs/pen/PaMmRo?editors=0010
@rbiggs Can't we avoid that?
/cc @ngryman @lukejacksonn
EDIT: Sorry different Luke who got mentioned.
Well, Preact doesn't bother supporting xlink:href at all. But Inferno and React do. SVG 2 is only supported by Chrome and Firefox. Microsoft has said they have no intention of supporting it, while Webkit has taken a wait and see approach. The reason is the spec for SVG 2 is still not finalized and apparently may never be. See full story here: https://www.reddit.com/r/linux/comments/5cuteh/is_svg_2_really_on_life_support/
@rbiggs have you tried to use throwIfNamespace: false
option in babel-plugin-transform-react-jsx
?
As much as I would love to just use SVG 2 and forget about this issue.. it always rears its head in an ugly way, making it a pain to implement icons reliably across browsers. Currently I am using the oncreate
hack to add the xlink:href
prop manually.
@lukejacksonn I should've explained it better. I added xlink support. It works :)
I mentioned you to get your feedback about doing something like React's xlinkHref
for JSX xlink support.
Ahh.. cool! I am yet to try that out.. sounds great π―does react have a list of these custom properties like xlinkHref
that we could just copy?
Sorry, but why not just allow to use namespace in jsx in your project, why need to support special camelCased names for attributes?
Btw, I implemented hyperapp-tools/webpack-svg-loader
which uses .svg
files as they are and converts them into hyperapp jsx components under the hood. It allows you to view svg using native OS or IDE preview tool and modify the graphics in any visual editor at any moment of time without the need to touch svg code manually after it.
@frenzzy Totally. I am definitely not excited about xlinkHref
.
Why not just allow to use namespace in jsx in your project
Is it as simple as throwIfNamespace: false
? If so, we can close here.
Well, throwNamespace
is only available in Babel 7.0 Beta 53, which has been at stuck at that version for many months. I wouldn't expect users to have to use a Beta in production for a feature. That said, I guess we can just wait it out. Hopefully Babel 7 will ship sooner than later.
π
You might want to mention xlink
support with and without throwNamespace
so that it's clear to noobs.
@rbiggs Haha, I just learned about throwNamespace
myself. Sure, let's mention it.
Seems like you've added support for SVG 1 xlink:href. Nice since Safari on Mac and iOS only supports SVG 1. Works fine with
h
, you just have to escape the property with "", π. However, namespaced properties aren't allowed in JSX, so this doesn't work with it. In the P/React ecosystem they use a special attributexlinkHref
that gets converted toxlink:href
, avoiding the problem.You'd need to do something like this in the
updateProperty
function:You would use it like this:
The SVG would be in the HTML like this: