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

NuxtImage + IPX + SWR = return buffer #1400

Closed
bernhardberger opened this issue Jul 5, 2024 · 10 comments
Closed

NuxtImage + IPX + SWR = return buffer #1400

bernhardberger opened this issue Jul 5, 2024 · 10 comments

Comments

@bernhardberger
Copy link

bernhardberger commented Jul 5, 2024

When I enable SWR on our website IPX/nitro/whatever the culprit.. returns a buffer instead of an image:

image

Any ideas how to work around this? This has been a major issue for us, preventing is to run SWR on our website and customer projects..

@metkm
Copy link

metkm commented Jul 5, 2024

do you have reproduction? I can't seem to replicate the issue

@bernhardberger
Copy link
Author

bernhardberger commented Jul 5, 2024

Sure:
https://github.com/bernhardberger/nuxt-ipx-swr-buffer-minimal-reproduction

git clone https://github.com/bernhardberger/nuxt-ipx-swr-buffer-minimal-reproduction
cd nuxt-ipx-swr-buffer-minimal-reproduction
npm run build && node .output/server/index.mjs

-> hard reload (CTRL+SHIFT+R) a few times after 10 seconds -> image will be dead

@bernhardberger
Copy link
Author

related: nuxt/nuxt#27307

@bernhardberger
Copy link
Author

Imho this should be documented..

@bernhardberger
Copy link
Author

bernhardberger commented Jul 18, 2024

We have now solved this using a nitro onBeforeResponse hook that unwraps and streams the Buffer so we can still use swr caching on /_ipx/** generated images (so the image gets served from a cache and the user won't have to wait for the regenerated image every time)

We'll provide a code sample later when it's tested.

@manot40
Copy link

manot40 commented Nov 3, 2024

Hey @bernhardberger, did you already done working with nitro hook code sample? Thanks in advance.

EDIT: Just made simple nuxt module to cache optimized images from ipx request to disk, inspired by #795. (You'll need to download and run the example project since stackblitz seems not working with native .node file sharp uses)

@Nagell
Copy link

Nagell commented Nov 9, 2024

+1

@ItsRyanWu
Copy link

Hey @bernhardberger, did you already done working with nitro hook code sample? Thanks in advance.

EDIT: Just made simple nuxt module to cache optimized images from ipx request to disk, inspired by #795. (You'll need to download and run the example project since stackblitz seems not working with native .node file sharp uses)

You are my hero! You should consider making this a published module, it will save a lot of people's life!

@Baroshem
Copy link
Collaborator

Baroshem commented Dec 9, 2024

Closing as the solution was provided.

Feel free to reopen if needed :)

@Baroshem Baroshem closed this as completed Dec 9, 2024
@TheAlexLichter
Copy link
Member

I still think this should have first class support + the issue with returning a buffer should be resolved.
The former can be tracked in #795
The latter can be tracked in nitrojs/nitro#1894

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

No branches or pull requests

7 participants