🐛 Prevent SVG icons from leaking into DOM #9574
Merged
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.
What
Currently the SVG icons returned as a string as part of the connector spec where attached to the DOM using
dangerouslySetInnerHTML
. This lead to a couple of problems:styles
defined in one SVG are attached to the regular DOM, thus will affect all other elements on the page. You can actually see that in action e.g. chosing the Cart.com icon. If you now open the source type selection (and thus render all other icons too), styles from another icon will suddenly overwrite the styles from the Cart.com icon.How
Using a simple
img
tab where we set the SVG as a data URL on, will prevent both of those things from happening, since we don't allow DOM injection from SVG elements.The only drawback would be, that icons can't make use of some form of SVG animations anymore, which as far as I could tell none of the icons tried to do (and I guess we anyway don't want them to do).
Side-Note
I'd personally have preferred to enable the
react/no-danger
linting rule to bring double care to all futuredangerouslySetInnerHTML
calls, but unfortunately the rule doesn't work together with styled components, which we are using.