Please convince me that Next Image dx isn't terrible
Unanswered
Asari posted this in #help-forum
AsariOP
I have been using Next Image for several years, have read the documentation several times, and still find its use to be tedious and its dx abysmal. I'm ready to be proven otherwise and have a few questions along the way.
First, let's compare it to simply using
Next Image
1. Try to be simple like <img>
Result >> Error: Image with src "/images/placeholder.png" is missing required "width" property
2. Listen to provided Next Error for required width. Provide abstract number
Result >> Error: Image with src "/images/placeholder.png" is missing required "height" property
3. Listen to error for height. What do the width and height numbers do anyways?
Result >> Image with src "/images/placeholder.png" has either width or height modified, but not the other. If you use CSS to change the size of your image, also include the styles 'width: "auto"' or 'height: "auto"' to maintain the aspect ratio.
(Alternative) At this point, ask #gpt-help. I'll skip the results, but it gives obviously incorrect advice. Abort.
4. Finally! Still no idea what
I'd like to hear a discussion and am ready to be persuaded.
First, let's compare it to simply using
<img> using latest Next in app directory:// Works as expected, no problem at all
<div className="w-96">
<img src={images[0] ?? "/images/placeholder.png"} />
</div>Next Image
1. Try to be simple like <img>
<div className="w-96">
<img src={images[0] ?? "/images/placeholder.png"} />
</div>Result >> Error: Image with src "/images/placeholder.png" is missing required "width" property
2. Listen to provided Next Error for required width. Provide abstract number
<div className="w-96">
<Image src={images[0] ?? "/images/placeholder.png"}
alt="Alt is required by Next Image"
width={300}
/>
</div>Result >> Error: Image with src "/images/placeholder.png" is missing required "height" property
3. Listen to error for height. What do the width and height numbers do anyways?
<div className="w-96">
<Image
src={images[0] ?? "/images/placeholder.png"}
alt="Alt is required by Next Image"
width={300}
height={300}
/>
</div>Result >> Image with src "/images/placeholder.png" has either width or height modified, but not the other. If you use CSS to change the size of your image, also include the styles 'width: "auto"' or 'height: "auto"' to maintain the aspect ratio.
(Alternative) At this point, ask #gpt-help. I'll skip the results, but it gives obviously incorrect advice. Abort.
4. Finally! Still no idea what
width and height do to be required.<div className="w-96">
<Image
src={images[0] ?? "/images/placeholder.png"}
alt="Alt is required by Next Image"
width={300}
height={300}
style={{ width: "auto" }}
/>
</div>I'd like to hear a discussion and am ready to be persuaded.
2 Replies
AsariOP
(Ran out of text to also show LCP/priority error. This is just one example, but have found using Image to be tedious in almost every use case I've encountered)
American Crow
I don't love the DX either. I like the component itself and what it achieves under the hood but it has a lot of pitfalls.
Your errors are most likely related to the fact that next/image can automatically read props like
Your errors are most likely related to the fact that next/image can automatically read props like
width, blurDataUrland height from statically imported images import mountains from "../../public/mountains.jpg"; src={mountains}. However using relative paths src="/mountain.jpg" these attributes can't not be inferred anymore, because they are unknown at bulid time and you as the coder have to take care of them. So you pretty much fall into one pitfall after another if you don't know these details which can be sumorized as poor DX i'd agree