-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
[Bug][Feature request] Color issue with multiple SVG, how to prevent conflicting id when importing svg in a web page? #242
Comments
Hello @kopax, SVGR already prefixes all IDs using SVGO, do you use CLI ? Webpack? |
I use I am importing a few SVG like this: import { ReactComponent as CityBitexco } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBitecxo.svg';
import { ReactComponent as CityBlock1 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBlock1.svg';
import { ReactComponent as CityBlock2 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBlock2.svg';
import { ReactComponent as CityBlock3 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBlock3.svg';
import { ReactComponent as CityBlock4 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBlock4.svg';
import { ReactComponent as CityBlock5 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBlock5.svg';
import { ReactComponent as CityChart } from '@svg-stock/www-assets/static/illustrations/landing/city/cityChart.svg';
import { ReactComponent as CityHelicopter } from '@svg-stock/www-assets/static/illustrations/landing/city/cityHelicopter.svg';
import { ReactComponent as CityLeaeftArm } from '@svg-stock/www-assets/static/illustrations/landing/city/cityLeaftArm.svg';
import { ReactComponent as CityMoneyDollar } from '@svg-stock/www-assets/static/illustrations/landing/city/cityMoneyDollar.svg';
import { ReactComponent as CityMoneyEuro } from '@svg-stock/www-assets/static/illustrations/landing/city/cityMoneyEuro.svg';
import { ReactComponent as CityMoneyPound } from '@svg-stock/www-assets/static/illustrations/landing/city/cityMoneyPound.svg';
import { ReactComponent as CityNumber1 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityNumber1.svg';
import { ReactComponent as CityNumber2 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityNumber2.svg';
import { ReactComponent as CityNumber3 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityNumber3.svg';
import { ReactComponent as CityPalette } from '@svg-stock/www-assets/static/illustrations/landing/city/cityPalette.svg';
import { ReactComponent as CityStars } from '@svg-stock/www-assets/static/illustrations/landing/city/cityStars.svg';
import { ReactComponent as CityTable1 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityTable1.svg';
import { ReactComponent as CityTable2 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityTable2.svg';
import { ReactComponent as CityTable3 } from '@svg-stock/www-assets/static/illustrations/landing/city/cityTable3.svg';
import { ReactComponent as CityTotal } from '@svg-stock/www-assets/static/illustrations/landing/city/cityTotal.svg';
import { ReactComponent as CityTotalNoBg } from '@svg-stock/www-assets/static/illustrations/landing/city/cityTotalNoBg.svg';
import { ReactComponent as CityTotalCleared } from '@svg-stock/www-assets/static/illustrations/landing/city-animation/cityTotalCleared.svg';
import { ReactComponent as CityBg } from '@svg-stock/www-assets/static/illustrations/landing/city/cityBg.svg';
import { ReactComponent as CityWorldMap } from '@svg-stock/www-assets/static/illustrations/landing/city/cityWorldmap.svg'; I directly render the view with these components in my DOM. |
Try upgrading svgr, it should solve your issue. |
I am doing $ npm install --save-dev @svgr/webpack I have in my + "@svgr/webpack": "^4.1.0", Create react app v2.1.1 seems to be using v2.1.1 of @svgr/webpack: Installing the latest version of @svgr/webpack now give this: $ npm ls @svgr/webpack
[email protected] /home/dka/workspace/git.kopaxgroup.com/yeutech/www
└── @svgr/[email protected]
|
There is no workaround, except waiting for an update or do not use create-react-app. Anyway prefixing is automatically supported in latest versions of SVGR and it can be activated in SVGO config using older version (create-react-app prevents you from modifying any config, so if you use it you are stuck). |
That makes it clear and time saving. I will try to use svgo prior using svg in react application in create-react-app until we got an updated version in create-react-app. We'd like to avoid ejecting everytime we have an issue and so far we are doing good. |
Yeah running SVGO before SVGR is a good workaround. Also it will run only one time if you commit your optimized SVGs! |
Just updated svgr and I confirm this solved my issue. |
Color issue with multiple SVG
I am importing multiple SVG all exported from illustrator. I got a color issues on all the svg that follow the first one that contains gradient.
The ID (and more) exist in other SVG's exported with illustrator, which cause the first one to be applied to all the others instead of their real color. In a web page, importing multiple SVGs can conflict.
Possible solution
<svg />
into<object />
, can this be activated with an option or be applied by default for allReactComponent
we import?prefix
option that might helpIs this a problem svgr can already solved?
The text was updated successfully, but these errors were encountered: