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.

Nested svg content is rendered twice

See original GitHub issue

This is a wired and annoying bug. When using a svg nested into another svg component, the content of nested svg has been drawn twice for no reason. The more strange thing with it is that one of them has drawn without respect to its parent properties (like width, height, x, y, …). My code is very complex, so I provide a simple code to reproduce the problem.

<Svg width={100} height={100} viewBox={'0 0 100 100'}>
    <G key={'item touch zone'} onPress={() => {}} x={20} y={10}>
        <Svg
             key="item"
             width={"100%"}
             height={"100%"}
        >
             <Circle key="circle" cx="7" cy="10" r="8" fill={'green'}/>
         </Svg>
     </G>
</Svg>

here is the result, the right circle is what I really draw, the left one is drawn by itself!!!

screenshot_1545040931

I’m using version 8.0.10 (the latest one so far)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
msandcommented, Feb 4, 2019

@SaeedZhiany @ReggaePanda Think I managed to replicate and fix this. Can you test with v9.2.3?

1reaction
react-catcommented, Sep 1, 2019

@msand Had a similar problem, I have nested circles and in case I render more than one instance of my class with svg, some additional circles appeared.

<SvgTradeIcon diameter={25} connotation={"negative"} direction={"up"} />
<SvgTradeIcon diameter={60} connotation={"negative"} direction={"up"} />
<SvgTradeIcon diameter={80} connotation={"negative"} direction={"up"} />

cryptuoso

A solution was to add random Ids generated by simple Math.random() to Defs:

<Svg height={diameter} width={diameter}>
    <Defs>
        <RadialGradient
            id={`radialGrad${randomId}`}
            ...
        >
           ...
        </RadialGradient>
        <LinearGradient id={`linearGrad${randomId}`} x1="0" y1="0" x2="0" y2="0.8">
            ...
        </LinearGradient>
    </Defs>
    <Circle ... fill={`url(#radialGrad${randomId})`}/>
    <Circle ... fill={`url(#linearGrad${randomId})`} />
</Svg>

cryptuoso (1)

Hope that it would help someone with similar situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested svg content is rendered twice · Issue #880 - GitHub
This is a wired and annoying bug. When using a svg nested into another svg component, the content of nested svg has been...
Read more >
Do browsers render all SVGs twice? - Stack Overflow
Let's add a rule for the <g> element in the <defs >, which is inside a hidden <svg> with display: none . Double...
Read more >
If You're Inlining SVG Icons, How Do You Deal With Unique ...
Using the same svg in multiple places produces duplicate id's, but at the same time, the values of those titles and descriptions haven't...
Read more >
Rendering a d3 chart in two places makes it render twice in ...
You need to make sure that this is not the first SVG element as seen from the document , but the first element...
Read more >
Building SVG Components with React.js and d3.js - pganalyze
Mozilla's MDN has a good reference to all the element types available. The event system is very similar to what you're already used...
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