Skip to content
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

NextJS Image issue #377

Closed
kaloyanBozhkov opened this issue Mar 1, 2023 · 7 comments
Closed

NextJS Image issue #377

kaloyanBozhkov opened this issue Mar 1, 2023 · 7 comments
Labels

Comments

@kaloyanBozhkov
Copy link

kaloyanBozhkov commented Mar 1, 2023

Expected Behavior

I should be able to convert as many HTML elements with < Image /> inside as I want, and get dataURLs with the correct inner < Image /> alongside anything else in the same element.

What happens instead

Instead, toPng returns the dataURL for the first image within the Div that was converted to dataURL and downloaded. If an image is loaded through a regular < img/> or as a background-image, there is no problem. But if it is loaded with a < Image /> (from Next's "next/image"), then the resulting dataURL will always use the< Image /> of the first Div element that was converted toPng.

Possible Solution

The workaround I am going with currently is to load the image as a < img /> instead of using Next's < Image />, but it's obviously a suboptimal solution.

I considered that maybe some caching issue was causing this, but not that I could find with just a quick investigation.

Steps To Reproduce

given 2 images served through NextJS's "< Image /> ("next/image")
-> get dataURL through toPng and download image .1
-> get dataURL through toPng and download image .2

The two dataURLs returned should be the same, provided nothing else within the element, that is toPng'd, differs.

Additional Context

My element is as follows:
image

A page has multiple of the above element, which I want to toPng and download.
The .blurredImg is what is not being outputted correctly through toPng with the 2nd+ runs
The parent element has a before pseudo class which adds a border of sorts.

Your Environment

"html-to-image": "^1.11.11",
"next": "13.1.6",
"react": "18.2.0",
"react-dom": "18.2.0",

Browser: chrome (latest)

@biiibooo
Copy link
Contributor

biiibooo bot commented Mar 1, 2023

👋 @kaloyanBozhkov

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@solnishshka
Copy link

Hi! Faced a similar problem in next js. The inclusion of "includeQueryParams: true" in the list of options helped me solve it.

@kaloyanBozhkov
Copy link
Author

That works! I tested and can confirm.

Add "includeQueryParams: true" to toPng's options solves it.

@intuity-hans
Copy link

Can also confirm that this works 🎉

@eliobricenov
Copy link

eliobricenov commented Oct 7, 2023

OMG I was stuck on this for hours. This is solution! It seems nextjs relies on the query parameters to get the right image. Thank you so much!

That works! I tested and can confirm.

Add "includeQueryParams: true" to toPng's options solves it.

@dtong12
Copy link

dtong12 commented Mar 25, 2024

yep that was the fix!

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

No branches or pull requests

6 participants