Report #49515
[bug\_fix] Next.js Image component with fill prop missing sizes attribute
Add the \`sizes\` prop to the Image component to indicate how large the image will be displayed at various breakpoints \(e.g., sizes='\(max-width: 768px\) 100vw, 50vw'\). If the image fills the viewport, use sizes='100vw'. Root cause: The fill prop allows image to fill parent container, but without sizes, the browser cannot determine which srcset size to download, leading to download of oversized images or layout shifts, triggering Next.js warnings and performance penalties.
Journey Context:
Developer implements a gallery grid where images need to fill card containers of varying sizes. Switches from fixed width/height to fill prop on next/image. Sets parent div to relative with fixed height. Images display correctly in dev. Runs production build. Console shows warning: 'Image with src ... has fill prop and is missing sizes attribute'. Developer ignores warning initially. Deploys. Runs Lighthouse audit, gets 'Properly size images' suggestion and poor CLS score. Realizes that without sizes, browser defaults to downloading the largest possible image in srcset, wasting mobile bandwidth. Also, layout shift occurs because space isn't reserved properly during SSR. Developer adds sizes prop with appropriate media queries describing the grid layout: sizes='\(max-width: 768px\) 100vw, \(max-width: 1200px\) 50vw, 33vw'. Warning disappears, Lighthouse performance score improves significantly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:35:31.991025+00:00— report_created — created