Skip to content
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

Merged
merged 7 commits into from
Nov 20, 2024
Merged

Conversation

canerakdas
Copy link
Member

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 unoptimized

Validation

The images in the preview build should load without any problems

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npm run format to ensure the code follows the style guide.
  • I have run npm run test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@canerakdas canerakdas requested review from a team as code owners November 19, 2024 19:50
Copy link

vercel bot commented Nov 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Nov 20, 2024 7:17pm

Copy link
Member

@styfle styfle left a 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]>
Copy link

github-actions bot commented Nov 19, 2024

Lighthouse Results

URL Performance Accessibility Best Practices SEO Report
/en 🟢 100 🟢 100 🟢 100 🟢 91 🔗
/en/about 🟢 100 🟢 100 🟢 100 🟢 91 🔗
/en/about/previous-releases 🟢 98 🟢 100 🟢 100 🟢 92 🔗
/en/download 🟢 98 🟢 100 🟢 100 🟢 91 🔗
/en/blog 🟢 100 🟢 100 🟢 96 🟢 92 🔗

Copy link

github-actions bot commented Nov 19, 2024

Unit Test Coverage Report

Lines Statements Branches Functions
Coverage: 92%
90.79% (631/695) 72.44% (184/254) 94.53% (121/128)

Unit Test Report

Tests Skipped Failures Errors Time
143 0 💤 0 ❌ 0 🔥 5.553s ⏱️

@RedYetiDev
Copy link
Member

Can you please run npm run format? Thanks!

@styfle
Copy link
Member

styfle commented Nov 19, 2024

I think we can improve this in Next.js to avoid the custom code here.

See vercel/next.js#72970

@ovflowd
Copy link
Member

ovflowd commented Nov 20, 2024

@styfle should we hold off with this change then and wait for upstream change?

ijjk pushed a commit to vercel/next.js that referenced this pull request Nov 20, 2024
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]>
@ovflowd ovflowd added this pull request to the merge queue Nov 20, 2024
Merged via the queue into nodejs:main with commit 78c14bd Nov 20, 2024
15 checks passed
bmuenzenmeyer pushed a commit that referenced this pull request Nov 21, 2024
* 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]>
wyattjoh pushed a commit to vercel/next.js that referenced this pull request Nov 28, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants