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

breaking-change(plugin-svgo): handle potential errors from optimize #663

Merged
merged 2 commits into from
Jan 9, 2022

Conversation

mikaelbr
Copy link
Contributor

@mikaelbr mikaelbr commented Jan 7, 2022

Summary

svg.optimize() can in some cases return error, when passed SVG is invalid. There are some cases also, for instance when removing some namespace attributes that the SVG is invalid as a cause of that. When this happens data returned from plugin-svgo will be undefined, causing this to be undefined in the following iteration of the loop. This again causes obscure errors in some cases when running the following plugins.

This depends on fixing the types for svgo: DefinitelyTyped/DefinitelyTyped#58031

Note: Marked this as breaking-change as it explicitly throws an error. There are other ways to handle this (propagate error etc), but feels like showing error here is better than just ignoring it.

This PR does not fix consumers of plugin-svgo to handle error.

Test plan

Added test case to ensure invalid svg throws error.

@vercel
Copy link

vercel bot commented Jan 7, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/gregberge/svgr/HNFpWhTxkXQNFjUPHCdnw4hV6KWy
✅ Preview: https://svgr-git-fork-mikaelbr-svgo-error-gregberge.vercel.app

@gregberge
Copy link
Owner

Hello @mikaelbr, I don't think it is a real breaking change here.

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

Successfully merging this pull request may close these issues.

None yet

2 participants