Strange SVG Component Duplication
See original GitHub issueGiven:
// icons/index.js
export alerts from "./alerts.svg";
export apm from "./apm.svg";
export data from "./data.svg";
export infrastructure from "./infrastructure.svg";
export support from "./support.svg";
// some react component
import * as icons from "./icons/index.js";
//...
class Nav extends React.Component {
render() {
return (
<div>
{Object.keys(icons).map(k => React.createElement(icons[k], { key: k }))}
</div>
)
}
}
What is rendered is something like: But those should all be different SVGs.
I’m using react@15.5.4, webpack@2.6.1, webpack-dev-server@2.4.5, react-svg-loader@2.0.0-alpha.1.
// webpack.config.js
//...
module: {
rules: [
{
enforce: "pre",
test: /\.js$/,
use: [{ loader: "babel-loader" }],
include: [/src/],
},
{
test: /\.svg$/,
use: [
{ loader: "babel-loader" },
{
loader: "react-svg-loader",
query: {
jsx: true,
es5: false,
svgo: {
pretty: true,
plugins: [{ removeTitle: true }],
floatPrecision: 2,
},
},
},
],
},
],
},
//...
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:15 (2 by maintainers)
Top Results From Across the Web
Fix duplicate SVG ID collision in React | by Anton Ball - Medium
A gotcha with SVG fill ids that can mean unexpected results when inline SVGs are rendered onto the page.
Read more >Multiple SVG Components not working or render as expected
I'm having a strange problem; and haven't been able to get a solution for it. Context: NextJS App. I have 5 different svgs,...
Read more >If You're Inlining SVG Icons, How Do You Deal With Unique ...
It's not only bad, it's simply not valid HTML to have duplicate IDs — and sure won't pass the w3c validator, so i...
Read more >What's happening with my SVG components? : r/Frontend
It probably has to do with the contents of the SVG. Do they make use of id fields and there are duplicate IDs...
Read more >SVG Tutorial: How to Code SVG Icons by Hand
All SVG shapes are defined within the SVG element itself, like this: ... but there's a weird fill in between the two that...
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
In my case, it was a problem with the SVG icons, icons are duplicated with the ID, I have changed it with a unique id by opening them into an editor.
Workaround, generating unique Ids in the cleanupIDs Plugin of svgo:
Found this Solution in this Issue: https://github.com/svg/svgo/issues/674#issuecomment-324193597