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.

SVGInjector messes up id's inside defs

See original GitHub issue

The index of the injected svg seems to be inserted after id’s, which is breaking url references

eg:

fill: url(#green)

image.svg:

<defs>
    <linearGradient id="green">
        ...
    </linearGradient>
</defs>

But when injected:

<defs>
    <linearGradient id="green-0">
        ...
    </linearGradient>
</defs>

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yiotazcommented, Feb 3, 2016

I have the exact same issue. I have a radialGradient with an id where it is targeted throughout the svg file as a fill attribute with this id. How can I make this work?

0reactions
parashramcommented, Jul 1, 2022

For those in need, you need to modify the JS source of SVGInjector to exclude certain defs included by default. Check the var iriElementsAndProperties on line 284 of svg-injector.js.

Modify it by commenting out what you don’t want messed with, ensuring that your ID’s are unique across your project, as I’m sure you already do. For example:

var iriElementsAndProperties = {
    'clipPath': ['clip-path'],
    'color-profile': ['color-profile'],
    'cursor': ['cursor'],
    'filter': ['filter'],
    // 'linearGradient': ['fill', 'stroke'],
    'marker': ['marker', 'marker-start', 'marker-mid', 'marker-end'],
    'mask': ['mask'],
    'pattern': ['fill', 'stroke']
    // 'radialGradient': ['fill', 'stroke']
};

I had issue in SVG loading by svg-injector ver 1.1.3. So, followed this solution but now SVG’s colors aren’t displaying correctly. SVG Image don’t load on when injector override defs id=“a-1” color display correctly. and incorrect color displaying without injector override default id=“a” while image load properly. Can anyone suggest me the needful solution to avoid this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

conflicting ids in two different SVG files included in the same ...
SVG injectors like Iconic SVGInjector or the newer Iconfu SVGInject handle this issue by making the IDs unique when inserting the SVG into ......
Read more >
24251 (Reconsider SVG inclusion to get_allowed_mime_types)
There are some who think SVG should be included in core as an allowed mime type. ... through explanation that it is not...
Read more >
If You're Inlining SVG Icons, How Do You Deal With Unique ...
Personally I wouldn't use ids on svgs at all. If you need an icon to be clickable then wrap it in a span...
Read more >
Reference Svg File In Html - Atlantis Diving Centre
then the DTD will be downloaded from the URL specified in the system identifier. Stay up to date with the latest web design....
Read more >
Analysis Report Avnet Technology Showcase_Event_IN (002 ...
JA3 SSL client fingerprint seen in connection with other malware ... Let us know your email address so that we can follow up...
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