Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--multipass optimization produces artifacts #1815

Closed
nschloe opened this issue Nov 1, 2023 · 1 comment
Closed

--multipass optimization produces artifacts #1815

nschloe opened this issue Nov 1, 2023 · 1 comment

Comments

@nschloe
Copy link

nschloe commented Nov 1, 2023

When running

svgo --multipass a.svg  

on the SVG

a

it will produce extra artifacts:

b

(See, e.g., the axis labels.)

The problem does not occur without --multipass.

This is with svgo 3.0.2, node 21.0.0, on Arch Linux.

@SethFalco
Copy link
Member

SethFalco commented Nov 3, 2023

Thanks for reporting the bug and sharing an example SVG to reproduce the issue.

The issue was that the original SVG had some instances of <use> that referred to an ID to a node that didn't exist. If the offending node referenced #a… but later the cleanupIds plugin renames another node ID to a, this makes those bad references valid and unintentionally points them to a different node. This causes previously malformed nodes to effectively duplicate an existing node.

See: #1817

MRE

minimal.svg

<svg xmlns="http://www.w3.org/2000/svg">
  <defs>
    <path id="uwu" d="M 2.046875 0 L 10.609375 0 C 12.40625 0 13.734375 -0.5 14.734375 -1.59375 C 15.671875 -2.578125 16.203125 -3.921875 16.203125 -5.40625 C 16.203125 -7.703125 15.15625 -9.078125 12.734375 -10.015625 C 14.484375 -10.8125 15.359375 -12.1875 15.359375 -14.140625 C 15.359375 -15.546875 14.84375 -16.75 13.859375 -17.625 C 12.84375 -18.53125 11.5625 -18.953125 9.75 -18.953125 L 2.046875 -18.953125 Z M 4.46875 -10.796875 L 4.46875 -16.828125 L 9.15625 -16.828125 C 10.5 -16.828125 11.265625 -16.640625 11.90625 -16.140625 C 12.578125 -15.625 12.953125 -14.84375 12.953125 -13.8125 C 12.953125 -12.765625 12.578125 -11.984375 11.90625 -11.46875 C 11.265625 -10.96875 10.5 -10.796875 9.15625 -10.796875 Z M 4.46875 -2.125 L 4.46875 -8.65625 L 10.375 -8.65625 C 12.5 -8.65625 13.78125 -7.4375 13.78125 -5.375 C 13.78125 -3.359375 12.5 -2.125 10.375 -2.125 Z M 4.46875 -2.125"/>
  </defs>
  <use href="#a" x="378" y="464"/>
  <use href="#uwu" x="385" y="464"/>
</svg>

svgo.config.js

module.exports = {
  plugins: [
    "cleanupIds",
  ]
};

Edit: Just realized this is a duplicate of #1195 though, so I'll close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants