Skip to content

Commit 14c3cff

Browse files
authored
fix: include width param in Cloudflare image loader to resolve Next.js warnings (#190)
1 parent ee57bf2 commit 14c3cff

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pages/cloudflare/howtos/image.mdx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ const normalizeSrc = (src: string) => {
2727
};
2828

2929
export default function cloudflareLoader({ src, width, quality }: ImageLoaderProps) {
30-
if (process.env.NODE_ENV === "development") {
31-
// Serve the original image when using `next dev`
32-
return src;
33-
}
3430
const params = [`width=${width}`];
3531
if (quality) {
3632
params.push(`quality=${quality}`);
3733
}
38-
const paramsString = params.join(",");
39-
return `/cdn-cgi/image/${paramsString}/${normalizeSrc(src)}`;
34+
if (process.env.NODE_ENV === "development") {
35+
// Serve the original image when using `next dev`
36+
return `${src}?${params.join("&")}`;
37+
}
38+
return `/cdn-cgi/image/${params.join(",")}/${normalizeSrc(src)}`;
4039
}
4140
```
4241

0 commit comments

Comments
 (0)