withastro / roadmap

Ideas, suggestions, and formal RFC proposals for the Astro project.
290 stars 29 forks source link

Assets: Request for Stricter `getImage()` Attributes #638

Closed joe-bell closed 1 year ago

joe-bell commented 1 year ago

What version of astro are you using?

2.4.5

Are you using an SSR adapter? If so, which one?

Vercel

What package manager are you using?

pnpm

What operating system are you using?

Max

What browser are you using?

N/A

Describe the Bug

I recently shipped an example for plaiceholder using the experimental (and wonderful) "assets" feature https://github.com/joe-bell/plaiceholder/blob/main/examples/astro

One minor thing that I've had to patch around for now, is that an image's attributes are a bit looser than I would expect: https://github.com/joe-bell/plaiceholder/blob/main/examples/astro/src/pages/base64/multiple.astro#L18

CleanShot 2023-05-25 at 19 25 15@2x

My expectation here would be that getImage() is at least retrieving the height/width for me (that's what's outputted, but the types don't reflect that currently)

Thanks again for all your work on this feature, having a blast :rock

Link to Minimal Reproducible Example

https://github.com/joe-bell/plaiceholder/blob/main/examples/astro

Participation

Princesseuh commented 1 year ago

The problem is that we don't know what attributes the configured image service is returning. Sure, the default ones do return width, height, loading etc, but a custom one might not.

I've been trying to think of a way to allow users to extend that, but unfortunately the usual "allow users to define an interface and merge it" doesn't work because of how image services are loaded, so I'm still at the thinking phase on that one 😓