You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do not use React svg components for regularly used icons #5865
These are the most important cases to optimize because those items are widely used in the content and/or layout.
The next things to optimize are:
blog authors' social icons
admonitions
These are not as widely used, and sometimes only apply to a single page.
I'd like to use SVG sprites for them too, but I'm not sure inlining the sprites directly into the HTML is a great idea considering this adds weight to pages that may not use these features. Possible solutions could be:
to lazy load an external SVG sprite file
find a way to inline only what's used in a static page (unfortunately, <Head> does not permit to hoist and deduplicate SVG sprite defs)
Activity
slorber commentedon Dec 1, 2021
Interesting discussion related to this problem: https://twitter.com/_developit/status/1382838799420514317
slorber commentedon Feb 8, 2022
svg sprites look like a good solution: https://benadam.me/thoughts/react-svg-sprites/
slorber commentedon Sep 2, 2024
Related read: https://fotis.xyz/posts/introducing-svg-use/
slorber commentedon Jan 31, 2025
Some recent improvements for icons that are repeated multiple times per page:
These are the most important cases to optimize because those items are widely used in the content and/or layout.
The next things to optimize are:
These are not as widely used, and sometimes only apply to a single page.
I'd like to use SVG sprites for them too, but I'm not sure inlining the sprites directly into the HTML is a great idea considering this adds weight to pages that may not use these features. Possible solutions could be:
<Head>does not permit to hoist and deduplicate SVG sprite defs)felipecrs commentedon Feb 1, 2025
@slorber, are these improvements transparent upon Docusaurus upgrade or do they require site owners to adjust anything?
PS: I know they were not released yet.
slorber commentedon Feb 3, 2025
@felipecrs those are implementation details of theme components and do not change any public API. Unless they swizzled unsafe theme components, site owners have nothing to do when upgrading. Our versioning policy applies as usual, with minor releases aiming to be easy to adopt: https://docusaurus.io/community/release-process
felipecrs commentedon Feb 3, 2025
Awesome, thank you.
anonsyn commentedon Mar 8, 2025
But how can I customize this icon?
slorber commentedon Mar 14, 2025
@anonsyn in any case we always use the sprites through an intermediate
@theme/Icon/Xyzcomponent.This means that you can always swizzle them, and make the React component render an inline SVG with JSX, exactly like we did before:
Or you can provide a reference to your own SVG sprite ids, like we do now (more optimized)
If you want to inject new SVG sprites in your page you can use the plugin lifecycle like we do too: