Repository navigation
SVG: draw a <use> that references another <use>, or a later element - #2193
Merged
Merged
Conversation
A <use> was never registered under its own id, and a <use> in <defs> was skipped, so a clone of a clone, as Inkscape writes them, failed with ValueError: use ... references nonexistent ref id.
Outside <defs>, a <use> could only reference an element already built. Build a later element when it is first referenced, as for <defs>, so a clone that comes before the clone it references is drawn too.
andersonhc
requested changes
Nov 14, 2026
andersonhc
left a comment
Collaborator
There was a problem hiding this comment.
I found one small edge case: when a references a hidden element, build_xref() returns before registering the clone’s own ID. Another referencing that clone then fails with “nonexistent ref id.”
<defs>
<rect id="hidden" display="none" width="10" height="10"/>
<use id="clone" href="#hidden"/>
</defs>
<use href="#clone"/>Could we register the empty clone before returning and add a regression test? This should render nothing without raising an error.
andersonhc
approved these changes
Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
<use>that references another<use>fails withValueError: use ... references nonexistent ref id #use3396. Inkscape writes these for a clone of a clone, e.g. in the flags of the Vatican and the British Indian Ocean Territory in mledoze/countries, the cubemap figure of the WebGPU spec and the demo image of picnic.Two things were missing:
build_xref()never registered a<use>under its ownid, andhandle_defs()skipped a<use>in<defs>.<defs>, a<use>could only reference an element built before it. In the British Indian Ocean Territory flag,use3398referencesuse3396, which comes after it. Such an element is now built when it is first referenced, apart from its ancestors, as<defs>content already is.test_svg_use_of_usecovers a clone of a clone in the document, in<defs>, and one that references a later clone; all fail without the change. The five files above now convert.