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
[NEXT-699] next/image is unusable in Server Components with loader function
#41924
Comments
|
Getting the same thing, to get the image working it has to be a client component which is not what I want. |
|
Not optimal but as a workaround it seems to work if you set the loader in https://nextjs.org/docs/api-reference/next/image#loader-configuration |
|
Keep in mind that client components are still server-side rendered, so requiring |
next/image is unusable in Server Components with loader function next/image is unusable in Server Components with loader function
|
I create a repo to reproduce this bug https://github.com/jee-r/image-loader-test as you can see in this branch if we set the loader in build has succeeded |
|
TLDR: Client Components are not bad, they are the components that you already knew. They are pre-rendered as part of the initial HTML. With this context, it’s entirely fine to create your own client component around it: 'use client'
import Image from 'next/image'
const imageLoader = ({ src, width, quality }) => {
return `https://example.com/${src}?w=${width}&q=${quality || 75}`
}
export default function Page() {
return (
<Image
loader={imageLoader}
src="me.png"
alt="Picture of the author"
width={500}
height={500}
/>
)
}You can learn more in the documentation here: https://nextjs.org/docs/app/api-reference/components/image#loader. You can also set "loaderFile" globally: https://nextjs.org/docs/app/api-reference/components/image#loaderfile, however there is no performance win in doing so, it's purely convenience. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When using
next/imagewith a custom loader in a Server Component we get the following error:Expected Behavior
I expect a custom loader to be usable with server components.
Link to reproduction
https://codesandbox.io/s/cocky-bohr-g3tqkt?file=/app/post/ImageWrapper.tsx:275-287
To Reproduce
Go to
/postin the provided codesandbox.NEXT-699
The text was updated successfully, but these errors were encountered: