tanem / react-svg

:art: A React component that injects SVG into the DOM.

Home Page:https://npm.im/react-svg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

overriding componentDidMount break the rendering

leobenkel opened this issue · comments

I have a component class that is setting up its version of componentDidMount and the result is that ReactSVG does not render the content of the SVG file.
But as soon as I interact with the component, it renders it.

Is that a known problem ? I am starting with react so I might have messed something up.

If you add the attribute afterInjection={console.log}, is there any error printed to console?

Hard to know what's going on without seeing some code. Can you please provide a repro? You can fork the Basic Usage sandbox for that if you like.

afterInjection={console.log}

Hello, here is the error message:

react-svg.esm.js?cba7:99 Error: Parent node is null
    at eval (svg-injector.esm.js?96e0:310)
    at eval (svg-injector.esm.js?96e0:72) undefined

I assume this to be a duplicate of #1297. The error message is the same.

Maybe, in my case, the rendering is done properly as soon as I comment my componentDidMount method of the component.

I tried moving the <ReactSvg .../> in its own component to mitigate this problem but the result is the same, if the parent has a componentDidMount it does not work either.

@leobenkel as mentioned earlier, is it possible for you to provide some code that shows what's going on? That would help figure out where there might be an issue.

I have a Component as a class.
I override componentDidMount().
In this component I only have one instance of ReactSVG but there are more down the tree in sub-components.

When I comment out componentDidMount , it works. Otherwise, I need to click somewhere or interact with the component/sub-component to make it render. I tried interacting with sibling components, far away in the tree, that doesnt trigger the rendering.

@leobenkel just published a beta version that may fix the issue you're seeing if you want to give it a try? Details are here.

@tanem , the beta.1 version seems to fix the problem ! Thanks for a quick fix !

Great to hear 🎉

I'll publish a proper version today, all things going to plan.

Just published the fix in v14.0.0, I'll wait till I hear back before closing the issue.

Seems like this version is working :)

Great to hear! 🎉 I'll go ahead and close the issue.