viewBox stripped from HTML output (nextjs)
See original GitHub issueRecently noticed the viewBox attribute has been stripped from our rendered SVG elements. I’ve attempted to use the plugins option inside the svgo property as plugins: [{ "removeViewBox": false }]
but it throws an error on compilation for ‘Plugin name should be specified’ so I believe this setup should work?
Currently using
"babel-plugin-inline-react-svg": "2.0.1",
"next": "10.2.0",
.babelrc:
plugins: [
[
'inline-react-svg',
{
svgo: {
plugins: [
{
name: 'removeViewBox',
params: false,
}
],
},
},
],
['styled-components', { ssr: true }],
],
svg element:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15.557 15.556" width="15.557" height="15.556">
..
</svg>
output:
<svg xmlns="http://www.w3.org/2000/svg" width="15.557" height="15.556">
..
</svg>
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6
Top Results From Across the Web
SVG viewBox attribute getting stripped in HTML #1523
I have looked into it and it appears HTMLAsset.js is calling posthtml-parser with its own config of {lowerCaseAttributeNames: true} which causes ...
Read more >Next js app with SSR is not pre-rendering HTML, so web- ...
js app that uses server side rendering. When running the application both locally and in production (on vercel edge), the initial page response ......
Read more >next/image
When the browser chooses, it does not yet know the size of the image on the page, so it selects an image that...
Read more >next/legacy/image
The layout behavior of the image as the viewport changes size. ... that is invoked once the image is completely loaded and the...
Read more >Blog - Next.js 8
The Next.js serverless target outputs Serverless functions from pages ... As Next.js pre-renders HTML, it wraps pages into a default ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have same issues during bump up some libraries. so i just downgrade
babel-plugin-inline-react-svg
version^1.1.2
. it work normally.or if you want using latest version, change attribute name
params
toactive
https://github.com/svg/svgo/releases/tag/v2.0.0then will work fine.
@nikola1970 I didn’t really change much, outside the params property from my original answer, if it helps, my .babelrc looks like this:
Now when I view my SVGs in the browser, the viewBox is being rendered correctly. Still using