#Render SVG
3 messages · Page 1 of 1 (latest)
I’m not seeing anything in the provided docs that explicitly describes using the experimental Astro Container API to render SVGs for client-side use, so I can’t give a definitive “yes” based on these sources.
What the docs do say:
- Astro can import SVG files and use them as SVG components in
.astrofiles; Astro inlines the SVG markup into the HTML. [SVG components] - These SVG components behave like other Astro components and are rendered server-side; they are not directly usable inside UI framework components, but can be passed into them from
.astro. [SVG components] - The Container API (
experimental_AstroContainer) is for rendering Astro components in isolation, returning either a string (renderToString) or aResponse(renderToResponse). [Container API; renderToString; renderToResponse]
From this, we can say:
- You can render an Astro component that includes an imported SVG component (e.g.
<Logo />) viaexperimental_AstroContainer.renderToString()and get HTML that contains the inlined<svg>…</svg>markup. [SVG components; renderToString] - The docs do not describe any special handling to make that output “client-renderable” beyond what you’d normally do with HTML strings or responses; they only cover server-side rendering and testing scenarios.
So:
- Yes, you can use the Container API to render an Astro component that uses an SVG component and obtain the resulting SVG markup as a string/response.
- The knowledge sources do not explain any dedicated pattern for then wiring that into client-side rendering or hydration, so any further details on “rendered on the client” are not covered in the provided docs.