Nested s in SVG cause duplicate rendering

Summary:

Loading an SVG file that has <symbol>s inside of <symbol>s ends up rendering the objects both at their original coordinates in the symbol (not to spec) and at their <use>d coordinates (as expected).

Steps to reproduce:

  • open Inkscape
  • load without_defs.svg
  • compare with loading with_defs.svg

File attachments:

without_defs.svg

with_defs.svg

Raw without_defs.svg for reference:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="-1.5 -1.5 43 43" width="43" height="43" xmlns="http://www.w3.org/2000/svg">
  <symbol id="outer" viewBox="0 0 40 20" width="40" height="20">
    <symbol id="inner" viewBox="0 0 20 20" width="20" height="20">
      <rect x="1.5" y="1.5" width="17" height="17" fill="#777777" stroke="#777777" stroke-width="0.5"/>
    </symbol>
    <use xlink:href="#inner" x="20" y="20"/>
  </symbol>
  <use xlink:href="#outer" x="0" y="0"/>
</svg>

What happened?

Loading without_defs.svg, I see two boxes:

image

What should have happened?

There should be only one box, as when loading with_defs.svg:

image

with_defs.svg has an extra <defs> wrapper to protect the inner <symbol>, which seems to be a valid workaround. But it shouldn't necessary: <symbol> implicitly includes the meaning of <defs>.

Version info

Inkscape 1.4.2 (f4327f4, 2025-05-13)

                      Compile  (Run)
    GLib version:     2.84.0
    GTK version:      3.24.49 (3.24.49)
    glibmm version:   2.66.7
    gtkmm version:    3.24.9
    libxml2 version:  2.12.10
    libxslt version:  1.1.43
    Cairo version:    1.18.4 (1.18.4)
    Pango version:    1.56.3 (1.56.3)
    HarfBuzz version: 10.4.0 (10.4.0)

    OS version:       Windows 11 24H2