Skip to content

Commit cdd49f8

Browse files
authored
fix fill override and suppress sizes warning
1 parent 159a64a commit cdd49f8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

example/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const Home: NextPage = () => {
136136
<div key={idx}>
137137
<h2>{d.label}</h2>
138138
<div className="imgcontainer">
139-
<ProxyImage alt="stub" {...d} />;
139+
<ProxyImage alt="stub" {...d} />
140140
</div>
141141
</div>
142142
))}

src/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,26 @@ const ProxyImage = ({
284284
? { fill: true }
285285
: {};
286286

287-
return <Image src={file} loader={imageLoader} {...props} {...fillProp} />;
287+
// Suppress missing sizes warning if fill is set
288+
// as it doesn't matter for this image optimization
289+
//
290+
// See https://nextjs.org/docs/pages/api-reference/components/image#sizes
291+
const sizesProp =
292+
props.sizes != null
293+
? { sizes: props.sizes }
294+
: fillProp.fill
295+
? { sizes: '100%' }
296+
: {};
297+
298+
return (
299+
<Image
300+
src={file}
301+
loader={imageLoader}
302+
{...props}
303+
{...fillProp}
304+
{...sizesProp}
305+
/>
306+
);
288307
};
289308

290309
export { ProxyImage, IMGPROXY_ENDPOINT, buildProxyImagePath, handle };

0 commit comments

Comments
 (0)