๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป dev

[Nextjs Image] The request resource XX has type "image/svg+xml" but dangerouslyAllowSVG is disabled

The request resource XX has type "image/svg+xml" but dangerouslyAllowSVG is disabled

 

 

์ด๋ฏธ์ง€ placeholder๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด https://placehold.co/์—์„œ ๊ฐ€์ ธ์˜ค๋ ค๊ณ  ํ–ˆ์œผ๋‚˜, ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

next ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ ํ•ด๊ฒฐ๋ฐฉ์•ˆ์€ dangerouslyallowsvg์„ค์ •์„ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

ํ•˜์ง€๋งŒ ๋””ํดํŠธ ๋กœ๋”๊ฐ€ SVG ์ด๋ฏธ์ง€๋ฅผ ์ตœ์ ํ™”ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ฌธ๊ตฌ์™€ ํ•จ๊ป˜, ๊ทธ ์ด์œ ๋ฅผ ์„ค๋ช…ํ•˜๋Š”๋ฐ,

 

์ฒซ์งธ๋Š” SVG๋Š” vector ํฌ๋ฉง์œผ๋กœ ์ด๋ฃจ์–ด์กŒ๊ธฐ ๋•Œ๋ฌธ์— resize ํ•„์š”์„ฑ์ด ์—†๊ณ , 

๋‘ ๋ฒˆ์งธ๋กœ๋Š” HTML/CSS ์™€ ๊ฐ™์€ ํŠน์„ฑ ๋•Œ๋ฌธ์— ์ ์ ˆํ•œ CSP ํ—ค๋” ์—†์ด๋Š” ์ทจ์•ฝ์„ฑ์œผ๋กœ ์ด์–ด์งˆ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

 

๋”ฐ๋ผ์„œ src prop์ด SVG์ธ ๊ฒƒ์„ ์•Œ๋ฉด ์ตœ์ ํ™”ํ•˜์ง€ ์•Š์€ ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  contentSecurityPolicy์™€  contentDispositionType์„ ๋น„๋กฏํ•œ ์ถ”๊ฐ€์ ์ธ ์„ค์ •๋„ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

๋”๋ณด๊ธฐ

(์›๋ฌธ)

The default loader does not optimize SVG images for a few reasons.

First, SVG is a vector format meaning it can be resized losslessly.
Second, SVG has many of the same features as HTML/CSS, which can lead to vulnerabilities without proper Content Security Policy (CSP) headers.

Therefore, we recommended using the unoptimized prop when the src prop is known to be SVG. This happens automatically when src ends with ".svg".

However, if you need to serve SVG images with the default Image Optimization API, you can set dangerouslyAllowSVG inside your next.config.js:
module.exports = {
  images: {
    dangerouslyAllowSVG: true,
    contentDispositionType: 'attachment',
    contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
  },
}โ€‹

In addition, it is strongly recommended to also set contentDispositionType to force the browser to download the image, as well as contentSecurityPolicy to prevent scripts embedded in the image from executing.

๋ญ”๊ฐ€ ๋‹ค๋ฅธ ์ด๋ฏธ์ง€๋“ค์€ ๊ตณ์ด dangerousltAllowSVG ์„ค์ •์„ ํ‚ฌ ํ•„์š”๊ฐ€ ์—†๋Š”๋ฐ ๋ชจ๋‘ ์ ์šฉํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒŒ ๋ถ€์ ์ ˆํ•ด ๋ณด์˜€๋‹ค.

 

๐Ÿค” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ ์—†์„๊นŒ?

์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” https://placehold.co/ ์— ๋“ค์–ด๊ฐ€ ๋ณด๋‹ˆ ํ™•์žฅ์ž๋ฅผ ๋ณ€๊ฒฝํ•ด ์ค„ ์ˆ˜ ์žˆ๋Š” ์„ค์ •์ด ์žˆ๋‹ค. 

https://placehold.co/600x400/png ์ด๋Ÿฐ ์‹์œผ๋กœ ๋ณ€๊ฒฝ์„ ํ•ด์ฃผ๊ณ , ์œ„์—์„œ dangerousltAllowSVG ์„ค์ •์„ ์ œ๊ฑฐํ•ด ์คฌ๋”๋‹ˆ ์—๋Ÿฌ๊ฐ€ ์ œ๊ฑฐ๋˜์—ˆ๋‹ค.

 

https://placehold.co/600x400?text=random/png๋กœ๋Š” ๋˜ ๋‹ค์‹œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ด์„œ ์–ด์ฉ” ์ˆ˜ ์—†์ด ์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋‹ค์‹œ ์„ค์ •ํ•ด์คฌ๋‹ค.


๐Ÿ“š References

https://placehold.co/

 

Placehold | A simple, fast and free image placeholder service

 

placehold.co

https://nextjs.org/docs/app/api-reference/components/image#dangerouslyallowsvg

 

Components: <Image> | Next.js

Optimize Images in your Next.js Application using the built-in `next/image` Component.

nextjs.org