Skip to content

Commit 7bee4c3

Browse files
Princesseuhsarah11918florian-lefebvreArmandPhilippot
authored
feat(reference): Update astro:assets reference for new Astro 6.0 behavior (#12639)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Armand Philippot <git@armand.philippot.eu>
1 parent 5d03bde commit 7bee4c3

File tree

3 files changed

+161
-133
lines changed

3 files changed

+161
-133
lines changed

src/content/docs/en/guides/images.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ All native HTML tags, including `<img>` and `<svg>`, are also available in `.ast
5151
For all images in `.astro` files, **the value of the image `src` attribute is determined by the location of your image file**:
5252

5353
- A local image from your project `src/` folder uses an import from the file's relative path.
54-
54+
5555
The image and picture components use the named import directly (e.g. `src={rocket}`), while the `<img>` tag uses the `src` object property of the import (e.g. `src={rocket.src}`).
5656

5757
- Remote and `public/` images use a URL path.
@@ -321,7 +321,7 @@ import myImage from '../assets/my_image.png'; // Image is 1600x900
321321

322322
Responsive images are images that adjust to improve performance across different devices. These images can resize to fit their container, and can be served in different sizes depending on your visitor's screen size and resolution.
323323

324-
With [responsive image properties](/en/reference/modules/astro-assets/#responsive-image-properties) applied to the `<Image />` or `<Picture />` components, Astro will automatically generate the required `srcset` and `sizes` values for your images, and apply the necessary [styles to ensure they resize correctly](#responsive-image-styles).
324+
With the [layout property](/en/reference/modules/astro-assets/#layout) applied to the `<Image />` or `<Picture />` components, Astro will automatically generate the required `srcset` and `sizes` values for your images, and apply the necessary [styles to ensure they resize correctly](#responsive-image-styles).
325325

326326
When this responsive behavior is [configured globally with `image.layout`](/en/reference/configuration-reference/#imagelayout), it will apply to all image components and also to any local and remote images using [the Markdown `![]()` syntax](/en/guides/images/#images-in-markdown-files).
327327

@@ -396,7 +396,7 @@ The global styles applied by Astro will depend on the layout type, and are desig
396396

397397
The styles use the [`:where()` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:where), which has a [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascade/Specificity) of 0, meaning that it is easy to override with your own styles. Any CSS selector will have a higher specificity than `:where()`, so you can easily override the styles by adding your own styles to target the image.
398398

399-
You can override the `object-fit` and `object-position` styles on a per-image basis by setting the `fit` and `position` props on the `<Image />` or `<Picture />` component.
399+
You can override the `object-fit` and `object-position` styles on a per-image basis by setting the `fit` and `position` props on the `<Image />` or `<Picture />` component.
400400

401401
#### Responsive images with Tailwind 4
402402

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ You may also wish to consider using glob packages from NPM, such as [`fast-glob`
375375
376376
In Astro 5.0, accessing `routes` on the `astro:build:done` hook was deprecated.
377377
378-
Astro 6.0 removes the `routes` array passed to this hook entirely. Instead, the `astro:routes:resolved` hook should be used.
378+
Astro 6.0 removes the `routes` array passed to this hook entirely. Instead, the `astro:routes:resolved` hook should be used.
379379
380380
#### What should I do?
381381
@@ -715,6 +715,39 @@ If you need more control over environment variables in Astro, we recommend you u
715715

716716
<ReadMore>Learn more about [environment variables](/en/guides/environment-variables/) in Astro, including `astro:env`.</ReadMore>
717717

718+
### Changed: Cropping by default in default image service
719+
720+
<SourcePR number="14629" title="feat(assets): Always allow cropping and never upscale" />
721+
722+
In Astro 5.0, the default image service would only apply cropping when the `fit` option was provided.
723+
724+
Astro 6.0 applies cropping by default without requiring setting the `fit` option.
725+
726+
#### What should I do?
727+
728+
No changes are needed to your existing cropped images as the `fit` property is still valid. However, if you were previously setting `fit` to `contain` (its default value) in order to crop your images, you may now remove this option and still achieve the same cropping behavior by specifying `width` and `height` alone:
729+
730+
```ts title="src/components/MyImage.astro" del={5} ins={6}
731+
---
732+
import { Image } from 'astro:assets';
733+
import myImage from '../assets/photo.jpg';
734+
---
735+
<Image src={myImage} width={400} height={300} fit="contain" />
736+
<Image src={myImage} width={400} height={300} />
737+
```
738+
739+
### Changed: Never upscale images in default image service
740+
741+
<SourcePR number="14629" title="feat(assets): Always allow cropping and never upscale" />
742+
743+
In Astro 5.0, the default image service would upscale images when the requested dimensions were larger than the source image.
744+
745+
Astro 6.0 removes this behavior: the default image service never upscales images.
746+
747+
#### What should I do?
748+
749+
Review your images and update dimensions as needed. If you do need to upscale images, you may consider upscaling the images manually or using a custom image service that supports upscaling.
750+
718751
### Changed: Markdown heading ID generation
719752

720753
<SourcePR number="14494" title="feat!: stabilize experimental.headingIdCompat"/>
@@ -792,7 +825,7 @@ If you want to keep the old ID generation for backward compatibility reasons, yo
792825
```
793826
</Fragment>
794827
</PackageManagerTabs>
795-
828+
796829
2. Create a custom rehype plugin that will generate headings IDs like Astro v5:
797830

798831
```js title="plugins/rehype-slug.mjs"
@@ -820,13 +853,13 @@ If you want to keep the old ID generation for backward compatibility reasons, yo
820853
};
821854
}
822855
```
823-
856+
824857
3. Add the custom plugin to your Markdown configuration in `astro.config.mjs`:
825858

826859
```js title="astro.config.mjs" ins={2} ins="rehypeSlug"
827860
import { defineConfig } from 'astro/config';
828861
import { rehypeSlug } from './plugins/rehype-slug';
829-
862+
830863
export default defineConfig({
831864
markdown: {
832865
rehypePlugins: [rehypeSlug],

0 commit comments

Comments
 (0)