Skip to content

Next.js: Upgrade image-size to 2.0 - #30741

Merged
valentinpalkovic merged 6 commits into
nextfrom
valentin/update-image-size-for-nextjs
Mar 6, 2025
Merged

Next.js: Upgrade image-size to 2.0#30741
valentinpalkovic merged 6 commits into
nextfrom
valentin/update-image-size-for-nextjs

Conversation

@valentinpalkovic

@valentinpalkovic valentinpalkovic commented Mar 3, 2025

Copy link
Copy Markdown
Contributor

Closes #

What I did

This PR upgrades image-size to 2.0.0, and removed the dependency on sharp for avif files.

Related PR storybookjs/vite-plugin-storybook-nextjs#32

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 79.9 MB 79.9 MB 0 B 0.56 0%
initSize 79.9 MB 79.9 MB 0 B 0.56 0%
diffSize 97 B 97 B 0 B - 0%
buildSize 7.57 MB 7.57 MB 0 B 1.22 0%
buildSbAddonsSize 1.98 MB 1.98 MB 0 B 1.22 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.88 MB 1.88 MB 0 B 0.42 0%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.06 MB 4.06 MB 0 B 1.22 0%
buildPreviewSize 3.51 MB 3.51 MB 0 B 1.22 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.3s 7.9s 574ms -1.22 7.2%
generateTime 19.2s 19.9s 677ms 0.48 3.4%
initTime 4.6s 4.6s -35ms 0.03 -0.8%
buildTime 10.3s 9.3s -984ms 0.12 -10.5%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5s 6s 1s 1.38 🔺17%
devManagerResponsive 4.8s 5.7s 948ms 1.35 🔺16.4%
devManagerHeaderVisible 724ms 857ms 133ms 0.3 15.5%
devManagerIndexVisible 732ms 872ms 140ms 0.14 16.1%
devStoryVisibleUncached 2.5s 2.8s 284ms 0.75 10%
devStoryVisible 1.1s 1.3s 215ms 0.42 15.8%
devAutodocsVisible 1.1s 1.4s 293ms 1.91 🔺20.3%
devMDXVisible 1.1s 1.3s 194ms 0.87 14.5%
buildManagerHeaderVisible 805ms 949ms 144ms 0.7 15.2%
buildManagerIndexVisible 824ms 965ms 141ms 0.68 14.6%
buildStoryVisible 795ms 945ms 150ms 0.77 15.9%
buildAutodocsVisible 793ms 797ms 4ms -0.04 0.5%
buildMDXVisible 766ms 864ms 98ms 0.88 11.3%

Greptile Summary

Updates Next.js image handling by upgrading image-size to v2.0.0 and removing the sharp dependency, simplifying AVIF image processing in the loader stub.

  • Upgraded image-size from 1.0.0 to 2.0.0 in code/frameworks/nextjs/package.json
  • Removed sharp dependency and its initialization code from code/frameworks/nextjs/src/next-image-loader-stub.ts
  • Simplified image dimension extraction to use single imageSize function call in code/frameworks/nextjs/src/next-image-loader-stub.ts
  • Removed special AVIF file handling, now processed through image-size's built-in support

@valentinpalkovic valentinpalkovic mentioned this pull request Mar 3, 2025
8 tasks
@valentinpalkovic valentinpalkovic self-assigned this Mar 3, 2025
@valentinpalkovic valentinpalkovic added nextjs maintenance User-facing maintenance tasks ci:normal Run our default set of CI jobs (choose this for most PRs). labels Mar 3, 2025

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@nx-cloud

nx-cloud Bot commented Mar 3, 2025

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 586d659.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 57s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-06 08:39:02 UTC

@valentinpalkovic valentinpalkovic added ci:normal Run our default set of CI jobs (choose this for most PRs). and removed ci:normal Run our default set of CI jobs (choose this for most PRs). labels Mar 4, 2025
@storybook-app-bot

storybook-app-bot Bot commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

Package Benchmarks

Commit: 586d659, ran on 6 March 2025 at 08:46:18 UTC

The following packages have significant changes to their size or dependencies:

@storybook/experimental-nextjs-vite

Before After Difference
Dependency count 177 167 🎉 -10 🎉
Self size 215 KB 215 KB 🎉 -56 B 🎉
Dependency size 48.71 MB 31.38 MB 🎉 -17.32 MB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 581 572 🎉 -9 🎉
Self size 454 KB 218 KB 🎉 -236 KB 🎉
Dependency size 82.96 MB 66.13 MB 🎉 -16.83 MB 🎉
Bundle Size Analyzer Link Link

@netroy

netroy commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

If you upgrade vite-plugin-storybook-nextjs to 1.1.2 in the same PR, it'll also remove image-size@1.1.1 and queue from the dependency tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). maintenance User-facing maintenance tasks nextjs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants