viewBox not rendered by default into SVG past v3.0.0
See original GitHub issueHi,
Not sure if this is an issue with this package, but recently upgraded from react-svg-loader@3.0.0
to react-svg-loader@3.0.3
and noticed that one of our SVGs now doesn’t get rendered properly in the page.
SVG:
<svg xmlns="http://www.w3.org/2000/svg" width="31" height="56" viewBox="0 0 31 56">
<path fill="#000" fill-rule="nonzero" d="M1.08 54.937a1.918 1.918 0 0 1 0-2.748l24.686-24.162L1.08 3.817a1.918 1.918 0 0 1 0-2.748 2.01 2.01 0 0 1 2.802 0L29.92 26.605c.387.38.58.853.58 1.374 0 .474-.193.995-.58 1.374L3.882 54.89a1.968 1.968 0 0 1-2.802.047z"/>
</svg>
Webpack config:
{
test: /\.svg$/,
use: [
"babel-loader",
{
loader: "react-svg-loader",
options: {
jsx: true
}
}
]
}
Usage:
import Chevron from "./images/chevron-right.svg";
...
<Chevron
...
className={"sort-container__option__chevron-right"}
/>
CSS:
.sort-container__option__chevron-right {
stroke: grey;
height: 20px;
width: 20px;
}
Expected output (@3.0.0)
<svg xmlns="http://www.w3.org/2000/svg" width="31" height="56" viewBox="0 0 31 56" class="sort-container__option__chevron-right"><path d="M1.08 54.937a1.918 1.918 0 0 1 0-2.748l24.686-24.162L1.08 3.817a1.918 1.918 0 0 1 0-2.748 2.01 2.01 0 0 1 2.802 0L29.92 26.605c.387.38.58.853.58 1.374 0 .474-.193.995-.58 1.374L3.882 54.89a1.968 1.968 0 0 1-2.802.047z"></path></svg>
Actual output (@3.0.3)
<svg xmlns="http://www.w3.org/2000/svg" width="31" height="56" class="sort-container__option__chevron-right"><path d="M1.08 54.937a1.918 1.918 0 0 1 0-2.748l24.686-24.162L1.08 3.817a1.918 1.918 0 0 1 0-2.748 2.01 2.01 0 0 1 2.802 0L29.92 26.605c.387.38.58.853.58 1.374 0 .474-.193.995-.58 1.374L3.882 54.89a1.968 1.968 0 0 1-2.802.047z"></path></svg>
Notice viewBox="0 0 31 56"
is missing from the output after 3.0.0
Visual differences (Top is with viewBox bottom is without):
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
What is default value of viewBox attribute if omitted from svg?
In the case of the SVG object itself this means the viewbox is equal to the view which is equivalent to viewing it...
Read more >SVG Viewport and viewBox (For Complete Beginners)
In this quick tutorial we're going to break down exactly what viewport and viewBox are in SVG.
Read more >Coordinate Systems, Transformations and Units — SVG 2
Unlike the transform property, the automatic transformation that is created due to a 'viewBox' does not affect the 'x', 'y', 'width' and 'height'...
Read more >viewBox - SVG: Scalable Vector Graphics - MDN Web Docs
The viewBox attribute defines the position and dimension, in user space, of an SVG viewport.
Read more >Viewbox tutorial: an introduction to the SVG coordinate space
What gets shown when an SVG image is rendered depends on values that ... default (0, 0) should be in the upper left...
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 FreeTop 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
Top GitHub Comments
@freshollie Seems to be a change in default options for SVGO, not a bug. Try this webpack configuration:
This bit me too, a changelog update would have been helpful.