Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

saveSvgAsPng makes svg's image fill disappear (d3.js) #234

Open
pavodev opened this issue Jan 9, 2020 · 9 comments
Open

saveSvgAsPng makes svg's image fill disappear (d3.js) #234

pavodev opened this issue Jan 9, 2020 · 9 comments

Comments

@pavodev
Copy link

pavodev commented Jan 9, 2020

I'm getting a strange behavior when triggering the saveSvgAsPng function.
I have two svg shapes (a circle and a triangle generated by d3.js) that are filled with 2 svg images. When the saveSvgAsPng function gets triggered, everything works perfectly except that these two shapes disappear and are not rendered in the exported png file. An other strange thing is that if I try to do "inspect element" all the DOM seems to disappear.
This happens in Firefox for MacOS.
In Chrome for MacOS the shapes doesn't disappear, but the filling images become blurred.

@vuquanghoang
Copy link

vuquanghoang commented Feb 27, 2020

@pavodev I also have the same issue. Did you use it with a react project?

@pavodev
Copy link
Author

pavodev commented Feb 27, 2020

Hi @vuquanghoang, yes I'm using it in a React project!

@vuquanghoang
Copy link

vuquanghoang commented Feb 27, 2020

The reason might be this library stores cache for stylesheet. Whenever we change the content, especially if we use styled-component, the className changes => no longer match. It cannot map style to inline => some shape / appearance missing. my current solution is set extra value for className on some elements use selectorRemap function. it might not good enough but working.

@exupero do you have any idea for this case? can we disable cache in option?

@pavodev
Copy link
Author

pavodev commented Feb 27, 2020

Actually I'm not using styled components. Most of the SVG styles are managed by d3js (the library I'm using to draw my SVGs) and I fear this is the root problem in my case since both d3js and React work in parallel on the DOM, this may complicate everything

@vuquanghoang
Copy link

I can see from the source code this line: if (cachedRules) return cachedRules;

I guess the cached stylesheet might be obsoleted after DOM changes couple of times.

@guslid
Copy link

guslid commented Apr 21, 2020

I just tested this library in a prototype I'm building and observed the issue on Firefox and Safari, but not on Chrome.

@pavodev
Copy link
Author

pavodev commented Apr 21, 2020 via email

@guslid
Copy link

guslid commented Apr 21, 2020

Are you also using React?

No, I'm not depending on React and not d3j.js either.

@pavodev
Copy link
Author

pavodev commented Apr 21, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants