Fix/16633 noimagemetadata for svg with either zero height or width#16681
Merged
Conversation
🦋 Changeset detectedLatest commit: 133c642 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 |
Contributor
Author
|
Please also see my feature suggestion that is made possible when this PR lands: withastro/roadmap#1359 |
When an SVG has explicit width="0" or height="0" attributes, the
image metadata extraction threw a NoImageMetadata error because both
check sites used JavaScript truthiness tests where 0 is falsy.
In vendor/image-size/types/svg.ts, the calculate() function fell
through the explicit-dimensions path when either dimension was 0 and
then hit the TypeError('Invalid SVG') throw.
In assets/utils/metadata.ts, the post-probe guard also rejected 0 via
the !result.height || !result.width condition.
Using 0 for width/height is a valid and recommended pattern for SVG
filter containers that should be hidden from screen readers:
<svg width="0" height="0" aria-hidden="true"></svg>
Fix: change both truthiness checks to null checks so that 0 is
accepted as an explicit dimension while null/undefined still signal
a missing value.
Fixes withastro#16633
daf5086 to
5163e3e
Compare
Contributor
Author
|
rebase on main |
Contributor
Author
|
@rururux Since you have last edited all of the lines in packages/astro/src/assets/utils/metadata.ts and packages/astro/src/assets/utils/vendor/image-size/types/svg.ts, could you please take a look at this PR? |
…r-zero-height-or-width
matthewp
approved these changes
May 14, 2026
This was referenced May 14, 2026
Merged
dadezzz
pushed a commit
to dadezzz/university_notes
that referenced
this pull request
May 22, 2026
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.3` → `6.3.5`](https://renovatebot.com/diffs/npm/astro/6.3.3/6.3.5) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.3.5`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#635) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.4...astro@6.3.5) ##### Patch Changes - [#​16771](withastro/astro#16771) [`07c8805`](withastro/astro@07c8805) Thanks [@​ematipico](https://github.com/ematipico)! - Fixes `position` prop on `<Image>` and `<Picture>` components breaking Content Security Policy (CSP). - [#​16593](withastro/astro#16593) [`50924ce`](withastro/astro@50924ce) Thanks [@​yanthomasdev](https://github.com/yanthomasdev)! - Improves error messages with more consistent and correct writing. - [#​16757](withastro/astro#16757) [`5d661cd`](withastro/astro@5d661cd) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes dev server serving stale content when SSR-only modules change (e.g. `.astro` files outside the project root in a monorepo, or dynamically imported components). Previously, the `astro:hmr-reload` plugin returned an empty array after detecting SSR-only module changes, which prevented Vite's `updateModules` from propagating the invalidation to the SSR module runner. The runner's evaluated module cache stayed stale, so subsequent requests continued returning old content. Now the plugin returns the SSR-only modules so Vite can process them through `updateModules`, which properly invalidates the module runner's cache and ensures fresh content on the next request. ### [`v6.3.4`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#634) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.3...astro@6.3.4) ##### Patch Changes - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `fetchFile` option to `experimental.advancedRouting` to customize or disable the entrypoint file ```js export default defineConfig({ experimental: { advancedRouting: { fetchFile: 'fetch.ts', }, }, }); ``` - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes Hono `cache()` middleware to follow the standard wrapper pattern - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `App.Providers` interface for typing custom context providers on `Astro` and `ctx` ```ts declare namespace App { interface Providers { oauth: import('./lib/oauth').OAuthSession; } } ``` - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `FetchState.response` property, set automatically after `pages()` or `middleware()` completes ```ts const response = await middleware(state, (s) => pages(s)); console.log(state.response === response); // true ``` - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `Fetchable` type export for typing the advanced routing entrypoint ```ts import type { Fetchable } from 'astro'; export default { async fetch(request) { return new Response('ok'); }, } satisfies Fetchable; ``` - [#​16572](withastro/astro#16572) [`4a5a077`](withastro/astro@4a5a077) Thanks [@​DORI2001](https://github.com/DORI2001)! - Suppresses `[WARN] Vite warning: unused imports from "@​astrojs/internal-helpers/remote"` during prerender builds. The package is now bundled alongside `astro` in the prerender environment, matching how it is handled in the SSR environment. - [#​16756](withastro/astro#16756) [`b6ee23d`](withastro/astro@b6ee23d) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes styles from Markdoc/MDX custom components not being extracted to `<head>` in the dev server when using the Cloudflare adapter with `prerenderEnvironment: 'node'` and rendering content through a wrapper component. - [#​16747](withastro/astro#16747) [`904d19a`](withastro/astro@904d19a) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes Astro action requests failing in `astro dev` when using the Cloudflare adapter with `prerenderEnvironment: 'node'` alongside a prerendered catch-all route such as `[...page].astro`. Actions and other SSR POST endpoints now continue to work in dev instead of returning an HTTP 500 error. - [#​16701](withastro/astro#16701) [`3495ce4`](withastro/astro@3495ce4) Thanks [@​demaisj](https://github.com/demaisj)! - Fix `Map` and `Set` instances saved in a content collection being broken when retrieving entries. - [#​16614](withastro/astro#16614) [`fca1c32`](withastro/astro@fca1c32) Thanks [@​Eptagone](https://github.com/Eptagone)! - Fixes `entry.data` type inference when a live collection is configured without a schema. - [#​16661](withastro/astro#16661) [`03b8f7f`](withastro/astro@03b8f7f) Thanks [@​ocavue](https://github.com/ocavue)! - Updates `typescript` to v6. No changes are needed from users. - [#​16681](withastro/astro#16681) [`c22770a`](withastro/astro@c22770a) Thanks [@​dotnetCarpenter](https://github.com/dotnetCarpenter)! - Fixes an issue where SVG images with `width="0"` or `height="0"` incorrectly threw a `NoImageMetadata` error instead of being treated as valid dimensions. </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-->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Awesome work by @OfirHaf and @fkatsuhiro! Fixing bug #16633 🎉
This PR is a curated combination of #16674 and #16676.
What does this fix?
Closes #16633
SVG elements with explicit
width="0"orheight="0"attributes threwNoImageMetadata: Could not process image metadatainstead of being imported normally. This is a valid and common pattern for SVG filter containers hidden from screen readers:Changes
issus: #16633
Root cause
Two falsy-zero checks along the metadata extraction path:
vendor/image-size/types/svg.ts— thecalculate()function:assets/utils/metadata.ts— post-probe validation:Changes
packages/astro/src/assets/utils/vendor/image-size/types/svg.ts: replace truthiness check with null check incalculate()packages/astro/src/assets/utils/metadata.ts: replace truthiness check with null check inimageMetadata()Both changes are minimal and surgical — they only affect the specific falsy-zero edge case while leaving all other behavior unchanged. SVGs with missing dimensions (null/undefined) still throw the appropriate error.
Testing
Befor implement testing
After implement testing