Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image component generates the unused original image only when reading the image property. #11887

Closed
1 task
tenpaMk2 opened this issue Aug 30, 2024 · 2 comments
Closed
1 task
Labels
needs triage Issue needs to be triaged

Comments

@tenpaMk2
Copy link

tenpaMk2 commented Aug 30, 2024

Astro Info

Astro                    v4.15.1
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

<Image> generates unused original images only when reading its property (like .width ).

Example

See the StackBlitz that is created from the empty project template.

Whether or not <Image> generates the original image depends on whether or not the .width property is read.

The following code generates the original image.

---
import myImage from "../sample.png";
import { Image } from "astro:assets";
---

...

<Image
  src={myImage}
  alt={`width is ${myImage.width}`}
  format="webp"
  widths={[240, 540]}
  sizes={`(max-width: 360px) 240px, 540px`}
/>

The following files are generated in the dist/_astro directory.

  • sample.DRk6a-UB.png <- The original image that is unused!!
  • sample.DRk6a-UB_2wRPSH.webp
  • sample.DRk6a-UB_AXNuM.webp
  • sample.DRk6a-UB_ZbJNag.webp

Strangely enough, if you delete ${myImage.width} , the original image is not generated.

Related issues?

What's the expected result?

The original image should not be generated in the _astro directory because it's never used in HTML.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-jovs8y?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 30, 2024
@Princesseuh
Copy link
Member

At the moment this is kinda intended, to be on the safer side regarding keeping images that might be needed. I think it would be possible to just limit it to src though.

@tenpaMk2
Copy link
Author

OK, thanks.
I will implement the following workarounds.
#4961 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants