-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Unoptimized SVG images #7244
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Co-authored-by: Steven <[email protected]> Signed-off-by: Caner Akdas <[email protected]>
Lighthouse Results
|
Can you please run |
I think we can improve this in Next.js to avoid the custom code here. |
@styfle should we hold off with this change then and wait for upstream change? |
The `<Image>` component doesn't optimize SVG images since they are vector images and can already scale up and down to any width. Therefore, the component will try to detect SVG images based on the file name to avoid sending them to the Image Optimization API at all. This is because the default behavior of the Image Optimization API is to error for SVG images due to the security implications of `<svg>` with nested `<script>`, etc (unless `dangerouslyAllowSVG` is enabled. However, we don't want users to reach for `dangerouslyAllowSVG` because it is not usually what they intended. So instead, we can improve the heuristic for detecting SVG in the `<Image>` component by ignoring the query string. Related to nodejs/nodejs.org#7244
Co-authored-by: Steven <[email protected]> Signed-off-by: Claudio W <[email protected]>
* fix: unoptimized SVG image * chore: review updates * Update apps/site/util/imageUtils.ts Co-authored-by: Steven <[email protected]> Signed-off-by: Caner Akdas <[email protected]> * chore: format files * chore: review update * Update apps/site/util/imageUtils.ts Co-authored-by: Steven <[email protected]> Signed-off-by: Claudio W <[email protected]> --------- Signed-off-by: Caner Akdas <[email protected]> Signed-off-by: Claudio W <[email protected]> Co-authored-by: Steven <[email protected]> Co-authored-by: Claudio W <[email protected]>
The `<Image>` component doesn't optimize SVG images since they are vector images and can already scale up and down to any width. Therefore, the component will try to detect SVG images based on the file name to avoid sending them to the Image Optimization API at all. This is because the default behavior of the Image Optimization API is to error for SVG images due to the security implications of `<svg>` with nested `<script>`, etc (unless `dangerouslyAllowSVG` is enabled. However, we don't want users to reach for `dangerouslyAllowSVG` because it is not usually what they intended. So instead, we can improve the heuristic for detecting SVG in the `<Image>` component by ignoring the query string. Related to nodejs/nodejs.org#7244
Description
With this PR, as discussed in #6454 (comment), instead of serving all images with
dangerouslyAllowSVG
, we now serve images with the.svg
extension as unoptimizedValidation
The images in the preview build should load without any problems
Check List
npm run format
to ensure the code follows the style guide.npm run test
to check if all tests are passing.npx turbo build
to check if the website builds without errors.