Skip to content

fix(assets): support images outside of the project in dev#14982

Merged
Princesseuh merged 2 commits intomainfrom
fix/image-outside
Dec 10, 2025
Merged

fix(assets): support images outside of the project in dev#14982
Princesseuh merged 2 commits intomainfrom
fix/image-outside

Conversation

@Princesseuh
Copy link
Member

Changes

When an image is using @fs, we can fetch it directly through Vite, that way it'll automatically respect Vite's limitations in regard to which files are allowed to be loaded.

Fixes #14957
Fixes #14937

Testing

We had a test for this already, but it didn't fetch the images (mostly because it was about path construction back in the day) so I updated it to actually try to fetch them

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2025

🦋 Changeset detected

Latest commit: c7d1a58

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 the pkg: astro Related to the core `astro` package (scope) label Dec 8, 2025

// Vite allows loading files directly from the filesystem
// as long as they are inside the project root.
if (isParentDirectory(fileURLToPath(root), src)) {
Copy link
Member Author

@Princesseuh Princesseuh Dec 8, 2025

Choose a reason for hiding this comment

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

I am not sure exactly what the code below here is trying to cover, because you cannot pass file paths anyway to getImage / Image so the only way you can hit it is by building a path manually, which won't anyway work in prod (well, it could, but then it wouldn't work in dev). I decided to leave it as-is just in case, but in my mind, we could remove it.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 8, 2025

CodSpeed Performance Report

Merging #14982 will not alter performance

Comparing fix/image-outside (c7d1a58) with main (ef53716)1

Summary

✅ 6 untouched

Footnotes

  1. No successful run was found on main (00c06ef) during the generation of this report, so ef53716 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Looks ok to me!

@Princesseuh Princesseuh merged commit 6849e38 into main Dec 10, 2025
45 of 47 checks passed
@Princesseuh Princesseuh deleted the fix/image-outside branch December 10, 2025 14:17
This was referenced Dec 10, 2025
dadezzz pushed a commit to dadezzz/ice-notes that referenced this pull request Dec 19, 2025
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`5.16.5` -> `5.16.6`](https://renovatebot.com/diffs/npm/astro/5.16.5/5.16.6) | ![age](https://developer.mend.io/api/mc/badges/age/npm/astro/5.16.6?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/astro/5.16.5/5.16.6?slim=true) |

---

### Release Notes

<details>
<summary>withastro/astro (astro)</summary>

### [`v5.16.6`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#5166)

[Compare Source](https://github.com/withastro/astro/compare/[email protected]@5.16.6)

##### Patch Changes

- [#&#8203;14982](withastro/astro#14982) [`6849e38`](withastro/astro@6849e38) Thanks [@&#8203;Princesseuh](https://github.com/Princesseuh)! - Fixes images outside the project directory not working when using astro:assets in development mode

- [#&#8203;14987](withastro/astro#14987) [`9dd9fca`](withastro/astro@9dd9fca) Thanks [@&#8203;Princesseuh](https://github.com/Princesseuh)! - Fixes SVGs not working in dev mode when using the passthrough image service

- [#&#8203;15014](withastro/astro#15014) [`a178422`](withastro/astro@a178422) Thanks [@&#8203;delucis](https://github.com/delucis)! - Adds support for extending the type of the props accepted by Astro’s `<Image>` component, `<Picture>` component, and `getImage()` API.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41Mi44IiwidXBkYXRlZEluVmVyIjoiNDIuNTIuOCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

2 participants