Only use create_element_ns if needed #3970
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Summary
Using
create_element_nsinBRaw::create_elementswithout a namespace and setting the inner HTML to the source for an SVG (with a properxmlnsattribute) fails in Chrome because the inner elements are fixed with no namespace. To address this issue, I've updatedBRaw::create_elementsto usecreate_elementwhen the parent namespace isNone.The Story
When I upgraded to yew 0.22, I found that SVGs were not rendering properly. The way I was including an SVG was as follows (simplified to remove the ability to choose the icon).
This renders properly in Firefox with both the old and new version, but does not render properly in Chrome with yew 0.22.
I was able to reproduce the issue that arose due to this commit. If you open a blank page in Chrome and run these commands at the console, an icon is added to the page.
If you change the first line to
createElementNSwithnullfor the namespace, an icon does not appear, but you can still see it if you inspect the page.Here is an image showing the
<svg>in the inspect pane that is not rendered.If you inspect the namespace of the two SVG elements, you can see that Chrome has left the namespace blank on the second one.
Checklist
I can't figure out a way to test this fix as it seems the tests are run in Firefox anyway.