-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Using React 15, under IE, dangerouslySetInnerHTML doesn't work on any SVG tag #6950
Labels
Comments
cc @spicyj |
Okay, we can change setInnerHTML to be along the lines of:
in the case of SVG and missing .innerHTML support (that is, only in IE). We should also create the container lazily. |
sophiebits
pushed a commit
that referenced
this issue
Jun 8, 2016
* Workaround IE lacking innerHTML on SVG elements * Add tests for setInnerHTML * Correctly check if node has innerHTML property * Ensure tests for setInnerHTML actually tests both codepaths * Provide mock element for setInnerHTML tests * Only use SVG setInnerHTML workaround for SVG elements
zpao
pushed a commit
to zpao/react
that referenced
this issue
Jun 8, 2016
…ebook#6982) * Workaround IE lacking innerHTML on SVG elements * Add tests for setInnerHTML * Correctly check if node has innerHTML property * Ensure tests for setInnerHTML actually tests both codepaths * Provide mock element for setInnerHTML tests * Only use SVG setInnerHTML workaround for SVG elements (cherry picked from commit 99d8524)
Sound fine, thank you! |
zpao
pushed a commit
that referenced
this issue
Jun 14, 2016
* Workaround IE lacking innerHTML on SVG elements * Add tests for setInnerHTML * Correctly check if node has innerHTML property * Ensure tests for setInnerHTML actually tests both codepaths * Provide mock element for setInnerHTML tests * Only use SVG setInnerHTML workaround for SVG elements (cherry picked from commit 99d8524)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Since React15, DOM reconciliation produce deep DOM manipulation instead of setting innerHTML of higher level html DOM node. Every DOM mutation is done exactly where it has to be done, either for HTML element or SVG element.
As a side effect, when you use dangerouslySetInnerHTML on any SVG element, React create the SVG element using document.createElementNS then set the innerHTML element of the new element. That's pretty cool on any recent browser, except IE. IE11 doesn't support innerHTML on any SVG tag. There is no script error as assigning an unknown property is always allowed on any Object. But nothing is added in the DOM tree.
for example, this stateless component produce an empty svg on IE:
here is a codepen demonstrating this issue
The goal is to add a string containing a literal SVG path (svgPath in the code) into a g tag wrapper inside a svg generic React component.
The first red icon is created using React15.
The second green icon is created using direct DOM manipulation and setting innerHTML on a g tag.
The third blue icon is created using direct DOM manipulation, without using the innerHTML on a g tag.
Avery modern browser is able to display the 3 icons, except Internet Explorer (any version), which is only capable to display the blue one.
The blue one use a hack to not use innerHTML directly on the g tag.
Here is a way to know if the browser supports or not innerHTML on svg tag:
A way to avoid this issue with current React 15 in a statefull component is to embed the hack describe here in the componentDidMount and eventually the componentDidUpdate methods.
Considering the exemple provided here, this statefull version is working:
and the codepen.io
Please notes that it's partially a regression, as dangerouslySetInnerHTML on an svg tag was working before React15 at the initial render (the svgPath string was added to the virtual DOM string, the whole virtual DOM generated by the render method was added to the real DOM using innerHTML of one of the the parents node). It was not working on a props update, except setting a key props on the high level svg tag, forcing react to use innerHTML of its parent (I was doing that without knowing why. Now, I do know).
Regards.
The text was updated successfully, but these errors were encountered: