Next.js Discord

Discord Forum

prevent <Image/> stretch

Unanswered
Golden northern bumble bee posted this in #help-forum
Open in Discord
Golden northern bumble beeOP
There are three stages of loading I am seeing

1. Spinner (expected)
2. Stretched images (not expected)
3. Proper image sizes (expected)

Is there a way to prevent step 2 from happening? It is causing some weird layout shift very quickly whenever loading.

Thanks!

It seems like the object-contain is not being applied instantly or something?

<div className="relative h-[50px] w-full max-w-[150px]">
    <Image
        src={gun.defaultPresetImageUrl}
        alt={gun.name}
        sizes="150px"
        className="object-contain"
        fill={true}
    />
</div>

2 Replies

Barbary Lion
Try removing fill={true} and change to object-cover
Golden northern bumble beeOP
need fill to be true since height and width are not specific, and I want to maintain aspect ratio so cover wont work :/