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

Path size regression in v2 or later #1436

Closed
silverwind opened this issue Mar 19, 2021 · 4 comments
Closed

Path size regression in v2 or later #1436

silverwind opened this issue Mar 19, 2021 · 4 comments
Labels

Comments

@silverwind
Copy link

Describe the bug

While upgrading from svgo@1.3.2 to svgo@2.2.2, I notice a size increase because path entries are no longer compressed as well as before. Used plugins are the same as before with the only difference being the mandatory extendDefaultPlugins usage.

To Reproduce

Example diff:

-<svg viewBox="0 0 16 16" class="svg octicon-book" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M0 1.75A.75.75 0 01.75 1h4.253c1.227 0 2.317.59 3 1.501A3.744 3.744 0 0111.006 1h4.245a.75.75 0 01.75.75v10.5a.75.75 0 01-.75.75h-4.507a2.25 2.25 0 00-1.591.659l-.622.621a.75.75 0 01-1.06 0l-.622-.621A2.25 2.25 0 005.258 13H.75a.75.75 0 01-.75-.75V1.75zm8.755 3a2.25 2.25 0 012.25-2.25H14.5v9h-3.757c-.71 0-1.4.201-1.992.572l.004-7.322zm-1.504 7.324l.004-5.073-.002-2.253A2.25 2.25 0 005.003 2.5H1.5v9h3.757a3.75 3.75 0 011.994.574z"/></svg>
+<svg viewBox="0 0 16 16" class="svg octicon-book" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M0 1.75A.75.75 0 0 1 .75 1h4.253c1.227 0 2.317.59 3 1.501A3.744 3.744 0 0 1 11.006 1h4.245a.75.75 0 0 1 .75.75v10.5a.75.75 0 0 1-.75.75h-4.507a2.25 2.25 0 0 0-1.591.659l-.622.621a.75.75 0 0 1-1.06 0l-.622-.621A2.25 2.25 0 0 0 5.258 13H.75a.75.75 0 0 1-.75-.75V1.75zm8.755 3a2.25 2.25 0 0 1 2.25-2.25H14.5v9h-3.757c-.71 0-1.4.201-1.992.572l.004-7.322zm-1.504 7.324.004-5.073-.002-2.253A2.25 2.25 0 0 0 5.003 2.5H1.5v9h3.757a3.75 3.75 0 0 1 1.994.574z"/></svg>

Options:

{
  plugins: extendDefaultPlugins([
    'removeXMLNS',
    'removeDimensions',
    {
      name: 'addClassesToSVGElement',
      params: {
        classNames: [
          'svg',
          name,
        ],
      },
    },
    {
      name: 'addAttributesToSVGElement',
      params: {
        attributes: [
          {'width': '16'},
          {'height': '16'},
          {'aria-hidden': 'true'},
        ],
      },
    },
  ]),
}

Expected behavior
SVG Size to not increase

Screenshots
image

Desktop (please complete the following information):

  • SVGO Version 2.2.2
  • NodeJs Version 14
@TrySound
Copy link
Member

This is intentional change. See #1353
You can change default behaviour by providing noSpaceAfterFlags to convertPathData and mergePaths plugins

@silverwind silverwind changed the title Path size regression in v2 oder later Path size regression in v2 or later Mar 19, 2021
@silverwind
Copy link
Author

Thanks, that did it. I think I'll probably keep the new defaults. Here's what I did to restore old behaviour in case anyone needs it:

const {params: mergePathParams} = require('svgo/plugins/mergePaths.js');
const {params: convertPathDataParams} = require('svgo/plugins/convertPathData.js');

// in plugins array
{name: 'mergePaths', params: {...mergePathParams, noSpaceAfterFlags: true}},
{name: 'convertPathData', params: {...convertPathDataParams, noSpaceAfterFlags: true}},

@TrySound
Copy link
Member

@silverwind Why do you pass params from plugins? Defaults are spread this way internally. Also please do not rely on any package internals. 'svgo' module is the only public api.

@silverwind
Copy link
Author

You're right, I was over-complicating this. For some reason I was assuming params would replace the plugin's defaults so I thought a full set of options was needed.

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

No branches or pull requests

2 participants