-
-
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
<style>
discarded
#65
Comments
This is not a bug, SVG as React Component are inlined in the page and <svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<style>
/* <![CDATA[ */
circle {
fill: orange;
stroke: black;
stroke-width: 10px;
}
/* ]]> */
</style>
<circle cx="50" cy="50" r="40" />
</svg>
<svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="40" />
</svg> The previous example will display two orange circles in the page. The first SVG leaks on the second one. This is why SVGR remove all |
Hi @neoziro! Thanks for conjuring up that example – it seems like it makes a lot of sense to call |
Yeah why not, it could be a good solution 👍 |
Also note that there is the svgo prefixIds plugin which prefixes styles as a kind of polyfill for scoped CSS. |
@gregberge but how to fix dynamic inlinestyle? eg.
I think it can provide a configuration, remove style element by default, but keep it when needed. |
I just used
svgr
to convert a bunch of SVGs with CSS declarations in a<style>
tag in<defs>
. eg.By default these get discarded so my componentized result looks very different – lots of black text on black background and other general nasties…
Running a external pass of svgo first with this config, the
<style>
tag converts into inline versions and the problems go away:{ "plugins": [ { "inlineStyles": { "onlyMatchedOnce": false } } ] }
So now I wonder if this should be the default behaviour of
svgr
and maybe the above should merge into thesvgo
config this project uses. Or alternatively, I wonder ifsvgr
should preserve<style>
tags without changing the SVG structure – perhaps the current discard behaviour is just a bug?The text was updated successfully, but these errors were encountered: