Skip to content

Conversation

@ascorbic
Copy link
Contributor

Changes

Renames experimental responsive image layout option from "responsive" to "constrained"

The previous name was causing confusion, because it is also the name of the feature. The responsive layout option is specifically for images that are displayed at the requested size, unless they do not fit the width of their container, at which point they would be scaled down to fit. They do not get scaled beyond the intrinsic size of the source image, or the width prop if provided.

It became clear from user feedback that many people (understandably) thought that they needed to set layout to responsive if they wanted to use responsive images. They then struggled with overriding styles to make the image scale up for full-width hero images, for example, when they should have been using full-width layout. Renaming the layout to constrained should make it clearer that this layout is for when you want to constrain the maximum size of the image, but allow it to scale-down.

This also refactors and simplifies the generated styles.

Testing

Updated tests. Tested manually.

Docs

API docs updated. I will do a separate PR to update the experimental flag docs.

@changeset-bot
Copy link

changeset-bot bot commented Apr 23, 2025

🦋 Changeset detected

Latest commit: d1bc212

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Apr 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Apr 23, 2025

CodSpeed Performance Report

Merging #13677 will not alter performance

Comparing resp-image-styles (d1bc212) with main (42388b2)

Summary

✅ 6 untouched benchmarks

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Apr 23, 2025
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changesets both look great! One tiny comment below from me! (And, this feels like a good change to me.)


:warning: **BREAKING CHANGE FOR EXPERIMENTAL RESPONSIVE IMAGES ONLY** :warning:

The generated styles for image layouts are now simpler and easier to override. Previously it used CSS to set the size and aspect ratio of the images, but this is no longer needed. Now it just sets `object-fit` and `object-position`, and sets `max-width: 100%` for constrained images and `width: 100%` for full-width images.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great explanation of what's happening! My only nit is not being super clear on what "it" is referring to. (If it's "generated styles" then should be "they" for plural? If it's "layouts" that's also plural unless you just want to say "your layout used CSS". If it's Astro, then we haven't introduced that antecedent at all yet!)

Not a huge deal, but enough that I went, "wait a minute, what is "it" here?" so might be enough to be a bit distracting to readers.

Also, there's little guidance here as to what to do about this breaking change (if anything?). We could add something after this paragraph as another standalone paragraph so it stands out, like:

This is an implementation change only. However, it may affect any custom styles you have added to your responsive images. Please check your rendered images to determine whether any change to your CSS is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about now

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Reminder to update the RFC before shipping this new change

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fantastic to me!

@ascorbic ascorbic merged commit b16b5ef into main Apr 24, 2025
17 checks passed
@ascorbic ascorbic deleted the resp-image-styles branch April 24, 2025 14:00
@astrobot-houston astrobot-houston mentioned this pull request Apr 24, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
* feat: rename layout and refactor styles

* Fix Vercel test

* Fix jsdoc

* Update wording
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants