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

Babel plugin / Inferno fails with rendering SVG #31

Closed
Havunen opened this issue Dec 22, 2015 · 7 comments
Closed

Babel plugin / Inferno fails with rendering SVG #31

Havunen opened this issue Dec 22, 2015 · 7 comments

Comments

@Havunen
Copy link
Member

Havunen commented Dec 22, 2015

Inferno babel plugin 0.2.5 or Inferno 0.4.0 is failing when there is component with SVG inside.

class Component extends Inferno.Component {
        constructor(props) {
            super(props);
         }
         render() {
            return (
               <svg class="alert-icon">
                    <use xlink:href="#error"></use> // This should link to inline svg with ID error
                </svg>
            )
         }
}

 Inferno.render(<Component />, APP_ELEMENT);

Exception is thrown:

 ModuleParseError: Module parse failed: ****\node_modules\babel-loader\index.js?{"presets":["es2015"],"plugins":["babel-plugin-syntax-jsx","babel-pl
You may need an appropriate loader to handle this file type.
|             tag: 'use',
|             attrs: {
|                 [object Object]: '#error'
|             }
|         }, '            ']

Expected result:
It should render SVG element with use element refering to error id.

React has solved it this way: http://stackoverflow.com/questions/26815738/svg-use-tag-and-reactjs

Havunen

@ghost
Copy link

ghost commented Dec 22, 2015

@Havunen Can you try to render it without JSX and see if it throws so we now if it's the plugin causing this, or something in the core.

@trueadm
Copy link
Member

trueadm commented Dec 22, 2015

It appears to be an issue with the core Babel JSX plugin when it encounters xlink:href="#error" (likely the colon throwing the JSX parser off). I'll investigate in more detail now.

@trueadm
Copy link
Member

trueadm commented Dec 22, 2015

Ah, so the issues is this:

Namespace tags are not supported. JSX is not XML.

So Babel does not support namespaced tags.

https://babeljs.io/repl/#?experimental=true&evaluate=true&loose=false&spec=false&code=%3Csvg%20class%3D%22alert-icon%22%3E%0A%09%3Cuse%20xlink%3Ahref%3D%22%23error%22%3E%3C%2Fuse%3E%0A%3C%2Fsvg%3E%0A

@trueadm
Copy link
Member

trueadm commented Dec 22, 2015

As per React:

facebook/react#2250

I'll get xlinkHref attribute added so it achieves the same thing without breaking JSX. :) @Havunen how does that sound?

@ghost
Copy link

ghost commented Dec 22, 2015

Everything is fixed and should work out of the box now with the compiled build on the dev branch.
Found here. https://github.com/trueadm/inferno/tree/dev/dist

@trueadm If still issues, just leave me a msg on Skype. I will read it later on.

@Havunen
Copy link
Member Author

Havunen commented Dec 22, 2015

Really quick reply guys!
I will try it out later today :)

@Havunen
Copy link
Member Author

Havunen commented Dec 22, 2015

Great work guys! It seems to work in dev branch. Closing this issue.

@Havunen Havunen closed this as completed Dec 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants