fix(sharp): handle default formats differently#16665
Conversation
🦋 Changeset detectedLatest commit: 692bacb The changes in this PR will be included in the next version bump. This PR includes changesets to release 421 packages
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 |
5f560bc to
f2d18cd
Compare
…SR gets the proper format
|
|
||
| // always call rotate to adjust for EXIF data orientation | ||
| result.rotate(); | ||
| // get some information about the input |
There was a problem hiding this comment.
Due to a merge conflict resolution fail, we were checking metadata twice, the try catch has been moved lower so we still get the same behavior
| `Sharp doesn't support this format. The image will be used unoptimized. ` + | ||
| `Consider converting to WebP or placing in the public/ folder.`, | ||
| ); | ||
| return { data: inputBuffer, format: bufferFormat as ImageOutputFormat }; |
There was a problem hiding this comment.
The diff makes this unclear, but all of those early returns format have been changed to output the same format they have.
This does potentially results in a wrong file extension either way for SSG (we determined the file extension a long time ago by now), but this at least make is so SSR gets the proper mime types and the image do actually show even then, which is the goal.
| `SVG image processing is disabled, but the source for "${transform.src}" is an SVG. ` + | ||
| `Pass it through unchanged by setting \`format="svg"\` on the component, ` + | ||
| `or set \`image.dangerouslyProcessSVG: true\` to rasterize SVG sources.`, |
There was a problem hiding this comment.
nit: It's a bit weird using tagged templates and breaking them down on multiple lines with +
* feat: try something else * fix: return buffer format instead of asked format in error cases so SSR gets the proper format * fix: better error message * fix: update for feedback * chore: cleanup comments
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)) | [`6.3.5` → `6.3.6`](https://renovatebot.com/diffs/npm/astro/6.3.5/6.3.6) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.3.6`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#636) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.5...astro@6.3.6) ##### Patch Changes - [#​16774](withastro/astro#16774) [`8f77583`](withastro/astro@8f77583) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes markdown images with empty alt text (``) in content collections dropping the `alt` attribute entirely. The `alt=""` attribute is now correctly preserved in the rendered HTML output, which is important for accessibility (indicating decorative images). - [#​16776](withastro/astro#16776) [`3d10b5e`](withastro/astro@3d10b5e) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes HMR serving stale content when components are passed as props via `getStaticPaths()` - [#​16784](withastro/astro#16784) [`7453860`](withastro/astro@7453860) Thanks [@​ematipico](https://github.com/ematipico)! - Improved the printing of the build time if it goes over the 60 seconds. - [#​16665](withastro/astro#16665) [`3dbbcee`](withastro/astro@3dbbcee) Thanks [@​Princesseuh](https://github.com/Princesseuh)! - Fixes remote SVG sources erroring with `dangerouslyProcessSVG` after the v6.3 SVG-processing gate. The default Sharp service now resolves the output format from the source up-front when it can (URL extension, `data:` MIME, ESM metadata), and from the actual buffer at request time when it can't, so SVG sources pass through untouched without needing to set `image.dangerouslyProcessSVG: true` or an explicit `format="svg"`. The error message has also been updated to point at `format="svg"` as the simpler workaround when an SVG source is encountered without `dangerouslyProcessSVG` enabled. - [#​16777](withastro/astro#16777) [`1754b91`](withastro/astro@1754b91) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes HMR serving stale content for dynamically imported components through barrel files - [#​16730](withastro/astro#16730) [`068d924`](withastro/astro@068d924) Thanks [@​harshagarwalnyu](https://github.com/harshagarwalnyu)! - Fixes an issue where the `file()` content loader did not generate a valid JSON Schema for collections whose JSON or YAML data is a top-level array instead of an object. </details> --- ### Configuration 📅 **Schedule**: (UTC) - 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 [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xODIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjE4Mi4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Changes
Since the creation of
astro:assets, there has been many lingering issues regarding default output formats. The way the pipeline has to work for SSG / SSR, perf reasons etc, means that we typically don't know the format of the image for real if its remote, which is mostly fine except for one case: SVGs. Since we don't want to convert SVGs to WebP by default, and also the reverse, we often need to know what we're working with to set the default format.Previously, this wasn't that much of an issue, because imo, it's kinda edge casey and being remote images meant that anyway it's up to the user to authorize. However, now in 6.3 with
dangerouslyProcessSVG, it's actually problematic to not really know what we're dealing it, because it could mean a SVG go through when it shouldn't, but also the reverse!This PR tries to fix this through a few methods:
Testing
Updated and added tests for certain of the newly covered cases
Docs
N/A