Skip to content

Commit ab0a4e7

Browse files
author
tanem
committed
Ensure we always have an img parentNode
Prevents console errors due to a race condition between React rendering and SVGInjector's processing of it's request queue (it uses setTimeout).
1 parent 87ad275 commit ab0a4e7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ export default class ReactSVG extends Component {
4040

4141
const div = document.createElement('div')
4242
div.innerHTML = ReactDOMServer.renderToStaticMarkup(
43-
<img
44-
className={className}
45-
data-src={path}
46-
style={style}
47-
/>
43+
<div>
44+
<img
45+
className={className}
46+
data-src={path}
47+
style={style}
48+
/>
49+
</div>
4850
)
4951

50-
const img = this.container.appendChild(div.firstChild)
51-
52-
SVGInjector(img, {
52+
const imgWrapper = this.container.appendChild(div.firstChild)
53+
54+
SVGInjector(imgWrapper.firstChild, {
5355
evalScripts,
5456
each
5557
})

0 commit comments

Comments
 (0)