-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Description
- Accepted Date: 2023-09-12
- Reference Issues/Discussions: Rendering `.svg` files as components #667
- Author: @natemoo-re
- Champion(s): @natemoo-re
- Implementation PR:
Summary
Let's support importing and using .svg files as Astro components.
Background & Motivation
Users have reported that .svg files are currently difficult to use—this is a problem we should provide an optimized solution for. Working with .svgs doesn’t need to be difficult or bloat your client-side JavaScript.
The Astro team has discussed and experimented with an "icon" primitive since before Astro v1.0 shipped. Now that we have shipped 3.0 with full astro:assets support, I firmly believe all of the pieces are in place to finally make this happen.
Goals
- Allow users to import and render local
.svgfiles as if they were an Astro component - Allow passing props onto the root
<svg>element while overriding the existing props - Automate best practices for to minimize performance footguns
- Including many inlined
<svg>on a page can hurt browser parsing performance. We can automatically reduce the number of nodes by using<symbol>and<use>. - Inline
<svg>often havexmlnsandxmlns:xlinkandversionattributes. These are not needed in HTML5 and we can automatically drop them to save a few bytes.
- Including many inlined
- Support this in a backwards-compatible way, meaning the current public interface of an
.svgimport remains unchanged - Stretch: support rendering
.svgcomponents in frameworks without inlining them into the client side JavaScript- Creating framework components for
.svgicons is an anti-pattern. It’s a terrible idea that bloats your JavaScript and creates all sorts of headaches for HMR and clientside performance in production. - If we provide a great
<Icon>component for each supported framework, we’ll make it easy for users to avoid this anti-pattern. It’s so common now because there aren’t many other good solutions.
- Creating framework components for
Non-Goals
- Future:
@iconify/jsonsupport - Future:
unplugin-iconssupport? Making this as seamless as possible would be awesome but supporting local.svgfiles is a good place to start.
septatrix, eric-driussi, lorenzolewis, sanman1k98, daflyinbed and 6 moretysian, stramel, u3u, zadeviggers, xandermann and 41 morelorenzolewis and connor-baerlorenzolewis
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Stage 3: Accepted Proposals, Has RFC