Skip to content

External SVGs are not rendered #13280

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

Closed
MarkusRodler opened this issue Aug 20, 2019 · 4 comments
Closed

External SVGs are not rendered #13280

MarkusRodler opened this issue Aug 20, 2019 · 4 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-svg ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Milestone

Comments

@MarkusRodler
Copy link
Contributor

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

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Create a Blazor application
  2. Create a file named 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>
  1. Paste the following SVG / HTML snippet into the Index page
<svg>
    <use href="circle.svg#icon"></use>
 </svg>

Expected behavior

The browser treats this as normal html with external svg and renders it properly

Actual Behavior

The browser does not display the svg.

@MarkusRodler
Copy link
Contributor Author

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 🙏)

@christallire
Copy link

christallire commented Feb 15, 2020

I'm having same problem too. adding event handler works as a workaround.
Thanks @MarkusRodler

@captainsafia
Copy link
Member

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.

@captainsafia captainsafia added bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Apr 29, 2020
@mkArtakMSFT
Copy link
Contributor

Closing as we will be tackling this as part of #18271

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label May 14, 2020
@ghost ghost added the Status: Resolved label May 14, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-svg ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

6 participants