question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting html to `<svg><use xlink:href=...></svg>` produces empty SVG in Chrome

See original GitHub issue

Current behavior

In Chrome, setting html parameter to

<svg viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg">
  <use xlink:href="/test/icons.svg#account"></use>
</svg>

where icons.svg is

<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="account" viewBox="0 0 24 24">
    <path d="M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z" />
  </symbol>
</svg>

produces empty icon:

image

Expected behavior

There should be an icon, Firefox works as expected. Most probably the issue is related to https://github.com/sweetalert2/sweetalert2/pull/1930

Live demo

https://cerulean-secret-hip.glitch.me/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gvernicommented, Jun 15, 2020

Quick update, I tested it on Canary 85.0.x and works fine:

image

1reaction
gvernicommented, Apr 11, 2020

@limonte I spent quite a lot of hours trying to debug it, but I haven’t found anything that can fix it. The only workaround I found is to force chrome to re-render the <use> resetting the link after the element has been attached to the destination:

let useHref = useElem.getAttribute("xlink:href")
useElem.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "")
useElem.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", useHref)

I’ll keep doing some more investigation and experiment because I don’t really like this solution…

Read more comments on GitHub >

github_iconTop Results From Across the Web

svg image using xlink:href not working in chrome
EDIT: in my browser, if i visit this page in new tab, the image above displayed as a empty circle. after i click...
Read more >
On xlink:href being deprecated in SVG - CSS-Tricks
The attribute we always use for them, xlink:href , is deprecated. Indeed, MDN says:
Read more >
Styling SVG <use> Content with CSS - Codrops
To use an element you pass a reference to that element—an ID—inside the use 's xlink:href attribute, and you position that element using...
Read more >
<use> - SVG: Scalable Vector Graphics - MDN Web Docs
The element takes nodes from within the SVG document, and duplicates them somewhere else.
Read more >
The Best Way to Embed SVG on HTML (2021) - Vecta.io
What's the best way to embed SVGs in HTML 5? How does embedding SVGs using Img tags, Object tags, Inline SVG differs among...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found