-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(reusePaths): reuse defs tag if exists and remove redundant nodes #1785
Merged
Conversation
This file contains 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
This was referenced Sep 19, 2023
SethFalco
changed the title
fix: reuse defs tag in reusePaths
fix(reusePaths): reuse defs tag if exists
Sep 20, 2023
SethFalco
force-pushed
the
fix/reuse-paths
branch
3 times, most recently
from
September 20, 2023 15:00
5f01e36
to
86880fb
Compare
SethFalco
changed the title
fix(reusePaths): reuse defs tag if exists
fix(reusePaths): reuse defs tag if exists and remove redundant nodes
Sep 20, 2023
SethFalco
force-pushed
the
fix/reuse-paths
branch
2 times, most recently
from
September 20, 2023 17:15
75cabf7
to
16f566b
Compare
TrySound
approved these changes
Sep 22, 2023
SethFalco
force-pushed
the
fix/reuse-paths
branch
from
September 23, 2023 09:14
16f566b
to
35a27f9
Compare
nono
referenced
this pull request
in cozy/cozy-stack
Nov 13, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [svgo](https://svgo.dev) ([source](https://github.com/svg/svgo)) | [`3.0.2` -> `3.0.3`](https://renovatebot.com/diffs/npm/svgo/3.0.2/3.0.3) | [![age](https://developer.mend.io/api/mc/badges/age/npm/svgo/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/svgo/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/svgo/3.0.2/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svgo/3.0.2/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>svg/svgo (svgo)</summary> ### [`v3.0.3`](https://github.com/svg/svgo/releases/tag/v3.0.3) [Compare Source](https://github.com/svg/svgo/compare/v3.0.2...v3.0.3) Includes various bug fixes and optimizations for existing plugins. We're also revamped the documentation for the project. You can find it on [svgo.dev](https://svgo.dev/)! The frontend for svgo.dev is maintained in [svg/svgo.dev](https://github.com/svg/svgo.dev), contributions are welcome. #### What's Changed ##### Settings - **Remove Comments**, introduces `preservePatterns` parameter. Preserves legal comments by default, same as the previous behavior, but can now be overridden. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1812](https://github.com/svg/svgo/pull/1812) - **Remove Description**, set the `removeAny` parameter to `false` by default for accessibility. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1806](https://github.com/svg/svgo/pull/1806) ##### Bug Fixes - **Remove Raster Images**, removes inlined JPEG images. By [@​abejfehr](https://github.com/abejfehr) in [https://github.com/svg/svgo/pull/1742](https://github.com/svg/svgo/pull/1742) - **Cleanup IDs**, correctly handle when 2 IDs have been referenced in a single attribute. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1795](https://github.com/svg/svgo/pull/1795) - **Cleanup IDS**, correctly handle when we've encountered a reference to a node that doesn't exist. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1817](https://github.com/svg/svgo/pull/1817) - **Inline Styles**, treat style prop keys as case-insensitive. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1797](https://github.com/svg/svgo/pull/1797) - **Inline Styles**, remove all classes in multiclass selector. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1801](https://github.com/svg/svgo/pull/1801) - **Inline Styles**, ignore empty CSS blocks instead of adding empty style attribute. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1823](https://github.com/svg/svgo/pull/1823) - **Minify Styles**, removes unused class selectors when the document has no classes. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1800](https://github.com/svg/svgo/pull/1800) - **Prefix IDs**, reuse the same prefix when encountering an ID multiple times. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1814](https://github.com/svg/svgo/pull/1814) - **Remove Hidden Elements**, stops removing non-rendering elements like masks. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1793](https://github.com/svg/svgo/pull/1793) - **Reuse Paths**, creates a new ID if the current one is referenced by another element. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1784](https://github.com/svg/svgo/pull/1784) - **Reuse Paths**, removes redundant `defs` children after optimization. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1785](https://github.com/svg/svgo/pull/1785) - **Reuse Paths**, stops duplicating attributes into the shared definition. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1791](https://github.com/svg/svgo/pull/1791) - Don't crash on a `null`, `undefined`, or empty plugin. Instead, log a warning and ignore it. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/issues/1128](https://github.com/svg/svgo/issues/1128) ##### SVG Optimization - **Convert Transform**, omit spaces between functions. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1802](https://github.com/svg/svgo/pull/1802) - **Remove Scripts**, removes callbacks (`on*`) and `href` attributes with `javascript:` URIs. By [@​cakeinpanic](https://github.com/cakeinpanic) and [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1807](https://github.com/svg/svgo/pull/1807), [https://github.com/svg/svgo/pull/1818](https://github.com/svg/svgo/pull/1818), [https://github.com/svg/svgo/pull/1819](https://github.com/svg/svgo/pull/1819), [https://github.com/svg/svgo/pull/1820](https://github.com/svg/svgo/pull/1820) - **Convert One-Stop Gradients**, new plugin to convert gradients with one stop to a solid color, disabled by default. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1790](https://github.com/svg/svgo/pull/1790) ##### Performance - Various optimizations for path handling. By [@​marvinhagemeister](https://github.com/marvinhagemeister) in [https://github.com/svg/svgo/pull/1716](https://github.com/svg/svgo/pull/1716) and [https://github.com/svg/svgo/pull/1717](https://github.com/svg/svgo/pull/1717) ##### Chores - Revise the README. By [@​ADTC](https://github.com/ADTC) in [https://github.com/svg/svgo/pull/1731](https://github.com/svg/svgo/pull/1731) - Fix dead link to postcss-svgo in README. By [@​Lehoczky](https://github.com/Lehoczky) in [https://github.com/svg/svgo/pull/1770](https://github.com/svg/svgo/pull/1770) - Replace webpack loader library in README as previous was deprecated. By [@​tanyabouman](https://github.com/tanyabouman) in [https://github.com/svg/svgo/pull/1771](https://github.com/svg/svgo/pull/1771) #### Metrics Before and after using vectors from various sources, with the default preset of each respective version: | SVG | Original | v3.0.2 | v3.0.3 | Delta | |---|---|---|---|---| | [Arch Linux Logo](https://archlinux.org/art/) | 8.584 KiB | 4.748 KiB | 4.747 KiB | ⬇️ 0.001 KiB | | [Blobs](https://gitlab.gnome.org/GNOME/gnome-backgrounds/-/blob/main/backgrounds/blobs-d.svg) | 50.45 KiB | 42.949 KiB | 42.949 KiB | | | [Isometric Madness](https://inkscape.org/~Denis_Kuznetsky/%E2%98%85isometric-madness) | 869.034 KiB | 550.829 KiB | 550.699 KiB | ⬇️ 0.13 KiB | | [tldr-pages Banner](https://github.com/tldr-pages/tldr/blob/main/images/banner.svg) | 2.071 KiB | 1.07 KiB | 1.07 KiB | | | [Wikipedia Logo](https://en.wikipedia.org/wiki/File:Wikipedia-logo-v2.svg) | 161.552 KiB | 118.441 KiB | 118.441 KiB | | Before and after of the browser bundle of each respective version: | | v3.0.2 | v3.0.3 | Delta | |---|---|---|---| | svgo.browser.js | 643.5 kB | 651.7 kB | ⬆️ 8.2 kB | </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on Monday" in timezone Europe/Paris, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/cozy/cozy-stack). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9-->
sungik-choi
referenced
this pull request
in channel-io/bezier-react
Nov 16, 2023
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [svgo](https://svgo.dev) ([source](https://github.com/svg/svgo)) | [`3.0.2` -> `3.0.3`](https://renovatebot.com/diffs/npm/svgo/3.0.2/3.0.3) | [![age](https://developer.mend.io/api/mc/badges/age/npm/svgo/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/svgo/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/svgo/3.0.2/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svgo/3.0.2/3.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>svg/svgo (svgo)</summary> ### [`v3.0.3`](https://github.com/svg/svgo/releases/tag/v3.0.3) [Compare Source](https://github.com/svg/svgo/compare/v3.0.2...v3.0.3) Includes various bug fixes and optimizations for existing plugins. We're also revamped the documentation for the project. You can find it on [svgo.dev](https://svgo.dev/)! The frontend for svgo.dev is maintained in [svg/svgo.dev](https://github.com/svg/svgo.dev), contributions are welcome. #### What's Changed ##### Settings - **Remove Comments**, introduces `preservePatterns` parameter. Preserves legal comments by default, same as the previous behavior, but can now be overridden. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1812](https://github.com/svg/svgo/pull/1812) - **Remove Description**, set the `removeAny` parameter to `false` by default for accessibility. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1806](https://github.com/svg/svgo/pull/1806) ##### Bug Fixes - **Remove Raster Images**, removes inlined JPEG images. By [@​abejfehr](https://github.com/abejfehr) in [https://github.com/svg/svgo/pull/1742](https://github.com/svg/svgo/pull/1742) - **Cleanup IDs**, correctly handle when 2 IDs have been referenced in a single attribute. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1795](https://github.com/svg/svgo/pull/1795) - **Cleanup IDS**, correctly handle when we've encountered a reference to a node that doesn't exist. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1817](https://github.com/svg/svgo/pull/1817) - **Inline Styles**, treat style prop keys as case-insensitive. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1797](https://github.com/svg/svgo/pull/1797) - **Inline Styles**, remove all classes in multiclass selector. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1801](https://github.com/svg/svgo/pull/1801) - **Inline Styles**, ignore empty CSS blocks instead of adding empty style attribute. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1823](https://github.com/svg/svgo/pull/1823) - **Minify Styles**, removes unused class selectors when the document has no classes. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1800](https://github.com/svg/svgo/pull/1800) - **Prefix IDs**, reuse the same prefix when encountering an ID multiple times. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1814](https://github.com/svg/svgo/pull/1814) - **Remove Hidden Elements**, stops removing non-rendering elements like masks. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1793](https://github.com/svg/svgo/pull/1793) - **Reuse Paths**, creates a new ID if the current one is referenced by another element. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1784](https://github.com/svg/svgo/pull/1784) - **Reuse Paths**, removes redundant `defs` children after optimization. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1785](https://github.com/svg/svgo/pull/1785) - **Reuse Paths**, stops duplicating attributes into the shared definition. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1791](https://github.com/svg/svgo/pull/1791) - Don't crash on a `null`, `undefined`, or empty plugin. Instead, log a warning and ignore it. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/issues/1128](https://github.com/svg/svgo/issues/1128) ##### SVG Optimization - **Convert Transform**, omit spaces between functions. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1802](https://github.com/svg/svgo/pull/1802) - **Remove Scripts**, removes callbacks (`on*`) and `href` attributes with `javascript:` URIs. By [@​cakeinpanic](https://github.com/cakeinpanic) and [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1807](https://github.com/svg/svgo/pull/1807), [https://github.com/svg/svgo/pull/1818](https://github.com/svg/svgo/pull/1818), [https://github.com/svg/svgo/pull/1819](https://github.com/svg/svgo/pull/1819), [https://github.com/svg/svgo/pull/1820](https://github.com/svg/svgo/pull/1820) - **Convert One-Stop Gradients**, new plugin to convert gradients with one stop to a solid color, disabled by default. By [@​SethFalco](https://github.com/SethFalco) in [https://github.com/svg/svgo/pull/1790](https://github.com/svg/svgo/pull/1790) ##### Performance - Various optimizations for path handling. By [@​marvinhagemeister](https://github.com/marvinhagemeister) in [https://github.com/svg/svgo/pull/1716](https://github.com/svg/svgo/pull/1716) and [https://github.com/svg/svgo/pull/1717](https://github.com/svg/svgo/pull/1717) ##### Chores - Revise the README. By [@​ADTC](https://github.com/ADTC) in [https://github.com/svg/svgo/pull/1731](https://github.com/svg/svgo/pull/1731) - Fix dead link to postcss-svgo in README. By [@​Lehoczky](https://github.com/Lehoczky) in [https://github.com/svg/svgo/pull/1770](https://github.com/svg/svgo/pull/1770) - Replace webpack loader library in README as previous was deprecated. By [@​tanyabouman](https://github.com/tanyabouman) in [https://github.com/svg/svgo/pull/1771](https://github.com/svg/svgo/pull/1771) #### Metrics Before and after using vectors from various sources, with the default preset of each respective version: | SVG | Original | v3.0.2 | v3.0.3 | Delta | |---|---|---|---|---| | [Arch Linux Logo](https://archlinux.org/art/) | 8.584 KiB | 4.748 KiB | 4.747 KiB | ⬇️ 0.001 KiB | | [Blobs](https://gitlab.gnome.org/GNOME/gnome-backgrounds/-/blob/main/backgrounds/blobs-d.svg) | 50.45 KiB | 42.949 KiB | 42.949 KiB | | | [Isometric Madness](https://inkscape.org/~Denis_Kuznetsky/%E2%98%85isometric-madness) | 869.034 KiB | 550.829 KiB | 550.699 KiB | ⬇️ 0.13 KiB | | [tldr-pages Banner](https://github.com/tldr-pages/tldr/blob/main/images/banner.svg) | 2.071 KiB | 1.07 KiB | 1.07 KiB | | | [Wikipedia Logo](https://en.wikipedia.org/wiki/File:Wikipedia-logo-v2.svg) | 161.552 KiB | 118.441 KiB | 118.441 KiB | | Before and after of the browser bundle of each respective version: | | v3.0.2 | v3.0.3 | Delta | |---|---|---|---| | svgo.browser.js | 643.5 kB | 651.7 kB | ⬆️ 8.2 kB | </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on Monday after 10am before 7pm" in timezone Asia/Seoul, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/channel-io/bezier-react). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ed Sungik Choi <sungik.dev@gmail.com>
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.
If an SVG already had a
defs
tag, thereusePaths
plugin would create a new one anyway. This changes it so if adefs
tag is found to exist in the document already, reuse and append to it.This avoids having 2
defs
in the same document after optimizing, which is unexpected, and also reducing the SVG size further.When reusing paths in an existing
defs
tag, it kept around useless nodes that sometimes even broke the SVG. This removes the node if it's anhref
only, and removes it if it's anid
only pointing to anotherhref
, and points elements directly to thathref
instead.Example
The plugin used to output this before, which includes some redundant nodes that broke SVGs:
<use xlink:href="#a"/>
is literally doing nothing.<use id="b" xlink:href="#a"/>
this can go, and replace references of#b
with#a
.Metrics
Taking the SVG from the bug reports, this both fixes the problem while producing an even smaller final output. The test was performed with only
reusePaths
enabled.I've also tested this in combination #1784 which still works correctly.
Related
Notes