Skip to content

Loading SVG with next/image and dangerouslyAllowSVG #53041

Answered by styfle
nirajniroula asked this question in Help
Discussion options

You must be logged in to vote

When the src prop ends with .svg, then the next/image component will automatically set unoptimized.

if (isDefaultLoader && src.endsWith('.svg') && !config.dangerouslyAllowSVG) {
// Special case to make svg serve as-is to avoid proxying
// through the built-in Image Optimization API.
unoptimized = true
}

If you know the content type is svg but the src prop doesnt end with .svg (your first example), then you can add the unoptimized prop to get the same behavior.

I highly recommend you avoid dangerouslyAllowSVG config unless you understand the security risks.

I also created…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@nirajniroula
Comment options

@nirajniroula
Comment options

@styfle
Comment options

@RobsonOlv
Comment options

Answer selected by styfle
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
5 participants