Skip to content

JSON.stringify does not work for SVG image objects since Astro 5.7.0 #13979

@TheJiahao

Description

@TheJiahao

Astro Info

Astro                    v5.10.0
Node                     v20.19.1
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

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

No response

Describe the Bug

JSON.stringify does not work for SVG image objects (ImageMetadata) since Astro 5.7.0, possibly due to commit 406501a which unflagged the SVG component feature and added extra properties to SVG image objects.

For example, the following code (see Minimal Reproducible Example) works in Astro 5.6.2 but not 5.7.0 and later versions:

import svgimage from '../assets/astro.svg';

console.log("SVG Image JSON:", JSON.stringify(svgimage));

// 5.6.2: {"src":"...", ...}
// 5.10.0: undefined

The bug also breaks pages where content collection entries with images are serialized.

To reproduce:

  1. Go the Minimal Reproducible Example
  2. Run pnpm install
  3. Run pnpm run astro build --verbose
  4. Check the output

For expected result, replace pnpm install with pnpm install [email protected].

What's the expected result?

JSON.stringify should output a serialized string as in the version 5.6.2.

Link to Minimal Reproducible Example

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

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)feat: assetsRelated to the Assets feature (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions