External SVGs are rendered into the DOM but are not visually rendered by the browser (Chrome, Edge Chromium in my case).
It appears this issue is due to the way how the DOM is updated in BrowserRenderer.ts.
This issue seems very similiar to this issue: https://github.com/aspnet/Blazor/issues/366
I did some research and it appears this is maybe the reason:
let svgElem = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
let useElem = document.createElementNS('http://www.w3.org/2000/svg', 'use');
// This
useElem.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', 'circle.svg#icon');
// or this
useElem.setAttributeNS('http://www.w3.org/1999/xlink', href', 'circle.svg#icon);
// seems to be missing in BrowserRenderer.ts
A clear and concise description of what the bug is.
Steps to reproduce the behavior:
circle.svg within wwwroot Folder with this content:<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<symbol id="icon" fill="currentColor" viewBox="0 0 100 100">
<ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2"/>
</symbol>
</svg>
<svg>
<use href="circle.svg#icon"></use>
</svg>
The browser treats this as normal html with external svg and renders it properly
The browser does not display the svg.
I coincidentally discovered a workaround for this problem. If you add an eventhandler to the svg, then it will be rendered correctly. For example with a dummy one:
<svg @onclick="@(() => {})">
<use href="circle.svg#icon"></use>
</svg>
It is really only a workaround, but maybe it is useful for someone else. (And I hope the issue will be fixed soon 馃檹)
I'm having same problem too. adding event handler works as a workaround.
Thanks @MarkusRodler
Thanks for reporting this issue, @MarkusRodler.
I've been looking into SVG issues in general, of which not supporting external SVGs is a big one. For now, I'll ref this issue into #18271 as we'd like to tackle all the SVG-related issues in one go.
Closing as we will be tackling this as part of https://github.com/dotnet/aspnetcore/issues/18271
Most helpful comment
I coincidentally discovered a workaround for this problem. If you add an eventhandler to the svg, then it will be rendered correctly. For example with a dummy one:
It is really only a workaround, but maybe it is useful for someone else. (And I hope the issue will be fixed soon 馃檹)