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

linearGradient being removed but references remain #1711

Closed
pierceray opened this issue Nov 15, 2022 · 0 comments · Fixed by #1881
Closed

linearGradient being removed but references remain #1711

pierceray opened this issue Nov 15, 2022 · 0 comments · Fixed by #1881
Labels

Comments

@pierceray
Copy link

Describe the bug
When running svgo via a node script on an image that has a linearGradient it is being removed and the proper id doesn't appear to be used.

To Reproduce

I'm using the following in a snippet in a node script against the attached svg.

optimize(data, {
  multipass: true,
  plugins: [
    'preset-default',
    {
      name: 'prefixIds',
      params: {
        delim: '',
        prefix: 'icon-deprecated-legacy-icon-stars-xl-svg-',
        prefixClassNames: false
      }
    },
    'convertStyleToAttrs',
  ],
  path,
});

Original SVG
icon-stars-xl

<svg xmlns="http://www.w3.org/2000/svg" width="164" height="28" xmlns:xlink="http://www.w3.org/1999/xlink">
    <defs>
        <linearGradient id="c" x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="50%" stop-color="#EB0450" />
            <stop offset="50%" stop-color="#BCBCBC" />
        </linearGradient>
        <path d="M624.716 783.585h7.261c.442 0 .834.283.972.701l-.687.225.687-.225c.138.42-.012.88-.37 1.141l-5.875 4.253 2.246 6.884a1.01 1.01 0 01-.369 1.132 1.02 1.02 0 01-1.207.004l-5.874-4.252V776h.012c.438.005.826.289.96.704l2.244 6.881zm-6.432 0l2.244-6.881c.134-.415.522-.699.96-.704h.012v17.448l-5.874 4.252a1.028 1.028 0 01-1.207-.004 1.01 1.01 0 01-.369-1.132l2.246-6.884-5.875-4.253a1.018 1.018 0 01-.37-1.14l.687.224-.687-.225c.138-.418.53-.701.972-.701h7.261z" id="a" />
    </defs>
    <use xlink:href="#a" transform="translate(-610 -776)" id="b" stroke="none" stroke-width="1" fill-rule="evenodd" />
    <use class="star star-1" xlink:href="#b" fill="url('#c')" />
    <use class="star star-2" xlink:href="#b" transform="translate(32)" fill="url('#c')" />
    <use class="star star-3" xlink:href="#b" transform="translate(64)" fill="url('#c')" />
    <use class="star star-4" xlink:href="#b" transform="translate(96)" fill="url('#c')" />
    <use class="star star-5" xlink:href="#b" transform="translate(128)" fill="url('#c')" />
</svg>

Output:
icon-stars-xl-output

<svg xmlns="http://www.w3.org/2000/svg" width="164" height="28">
    <defs>
        <path id="icon-deprecated-legacy-icon-stars-xl-svg-a" d="M624.716 783.585h7.261c.442 0 .834.283.972.701l-.687.225.687-.225c.138.42-.012.88-.37 1.141l-5.875 4.253 2.246 6.884a1.01 1.01 0 0 1-.369 1.132 1.02 1.02 0 0 1-1.207.004l-5.874-4.252V776h.012c.438.005.826.289.96.704l2.244 6.881zm-6.432 0 2.244-6.881c.134-.415.522-.699.96-.704h.012v17.448l-5.874 4.252a1.028 1.028 0 0 1-1.207-.004 1.01 1.01 0 0 1-.369-1.132l2.246-6.884-5.875-4.253a1.018 1.018 0 0 1-.37-1.14l.687.224-.687-.225c.138-.418.53-.701.972-.701h7.261z" />
    </defs>
    <use id="icon-deprecated-legacy-icon-stars-xl-svg-b" fill-rule="evenodd" stroke="none" stroke-width="1" href="#icon-deprecated-legacy-icon-stars-xl-svg-a" transform="translate(-610 -776)" />
    <use fill="url(\'#c\')" class="star star-1" href="#icon-deprecated-legacy-icon-stars-xl-svg-b" />
    <use fill="url(\'#c\')" class="star star-2" href="#icon-deprecated-legacy-icon-stars-xl-svg-b" transform="translate(32)" />
    <use fill="url(\'#c\')" class="star star-3" href="#icon-deprecated-legacy-icon-stars-xl-svg-b" transform="translate(64)" />
    <use fill="url(\'#c\')" class="star star-4" href="#icon-deprecated-legacy-icon-stars-xl-svg-b" transform="translate(96)" />
    <use fill="url(\'#c\')" class="star star-5" href="#icon-deprecated-legacy-icon-stars-xl-svg-b" transform="translate(128)" />
</svg>

Steps to reproduce the behavior:

  1. Run the optimize function with the above config.
  2. Note that the linearGradient is removed from the optimized SVG and the Id of the linearGradient use was not prefixed.

Expected behavior
The SVG icons still renders as the original SVG.

Screenshots

Original:
icon-stars-xl

Output:
icon-stars-xl-output

Desktop (please complete the following information):

  • SVGO Version 3.0.1
  • NodeJs Version 16.18.1
  • OS: MacOS 12.6

Additional context
I reformatted the Output for clarity, but the content is the same.

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

Successfully merging a pull request may close this issue.

1 participant