ng-inline-svg icon indicating copy to clipboard operation
ng-inline-svg copied to clipboard

2 fragments using the same name but from 2 different files conflicts

Open Xample opened this issue 6 years ago • 8 comments

<div [inlineSVG]="'assets/icons/thermometer/thick.svg#arrival'" [cacheSVG]="false"></div>
<div [inlineSVG]="'assets/icons/thermometer/thin.svg#arrival'" [cacheSVG]="false"></div>

Renders

image

while inverting those lines

<div [inlineSVG]="'./thin.svg#arrival'" [cacheSVG]="false"></div>
<div [inlineSVG]="'./thick.svg#arrival'" [cacheSVG]="false"></div>

gives: image

despite the cache to be disabled, the first object will be reused by the second one

SVGs.zip

Xample avatar Jan 15 '19 12:01 Xample

might it be because of the #arrival symbol? although as i noticed the svg images have different names, they are being symbolized by the same unique chars

cyphercodes96 avatar Jan 16 '19 14:01 cyphercodes96

It could be 2 times #departure the result will be the same. I suspect some cache to use the fragment name as the key.

Xample avatar Jan 16 '19 17:01 Xample

This is indeed because of the same IDs, which this directive doesn't try to distinguish between. It'll use whichever instance of the ID shows up first on the page (since they're injected directly into the DOM).

Ideally, the symbol IDs would be different.

arkon avatar Apr 07 '19 20:04 arkon

@arkon sometimes we do not choose the name of the fragment. The namespace should be the file path (url) which will be unique per svg file, not the fragment (symbol) name

Xample avatar Apr 07 '19 20:04 Xample

Under the hood, it's just using the regular <use> tag, so the file path has no real relevance.

I could randomize the IDs after, but that may cause some confusion with styling.

EDIT: this is a side effect of https://github.com/arkon/ng-inline-svg/commit/95c7a2f6096eb529971ad69dd8d4a5f736a81d2b

arkon avatar Apr 07 '19 20:04 arkon

why setting [cacheSVG]="false" doesn't work? What's the expected behavior? I also ran into the same issue with some common ids among my svgs and wrong cache rendered.

fatpandaria avatar Jan 15 '20 05:01 fatpandaria

The cache is irrelevant to how things are rendered. Still not entirely sure how this should be solved.

arkon avatar Jan 15 '20 23:01 arkon

From #114:

The svg injector should support the prevention of id conflicts. It is common usage of the module to include svgs from multiple sources. The usage of svgs from different sources creates the risk of colliding ids inside the svg elements.

For example SVGInject makes all IDs inside the svg unique, before they are injected into the HTML.

I stumbled across this problem while using different svgs, which had a clipPath definition with the same id. The latter svg therefore wasn't displayed.

arkon avatar Jan 15 '20 23:01 arkon