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

Nextjs-Vite: Add Next.js 15 support #29640

Merged
merged 6 commits into from
Nov 20, 2024
Merged

Nextjs-Vite: Add Next.js 15 support #29640

merged 6 commits into from
Nov 20, 2024

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Nov 18, 2024

Closes #

What I did

This PR adds Next.js 15 support to the nextjs-vite framework. This requires changes in the vite-plugin-next repo which are accounted for in storybookjs/vite-plugin-storybook-nextjs#27

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 pull request has been released as version 0.0.0-pr-29640-sha-e762e5df. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-29640-sha-e762e5df
Triggered by @yannbf
Repository storybookjs/storybook
Branch yann/next-15-support-vite
Commit e762e5df
Datetime Tue Nov 19 15:56:35 UTC 2024 (1732031795)
Workflow run 11916826559

To request a new release of this pull request, mention the @storybookjs/core team.

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

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.4 MB 78.4 MB 0 B 0.28 0%
initSize 144 MB 144 MB -169 kB 0.2 -0.1%
diffSize 65.3 MB 65.2 MB -169 kB -0.2 -0.3%
buildSize 7.03 MB 6.88 MB -156 kB -0.18 -2.3%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.06 MB 1.9 MB -156 kB -0.23 -8.2%
buildSbPreviewSize 271 kB 271 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.04 MB 3.88 MB -156 kB -0.23 -4%
buildPreviewSize 3 MB 3 MB -148 B 0.9 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 25.8s 26.1s 247ms 1.31 0.9%
generateTime 22.9s 19.5s -3s -349ms -0.53 -17.1%
initTime 14.9s 13.4s -1s -480ms -0.87 -11%
buildTime 8s 9s 1s 0.11 11.5%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.8s 6.1s -725ms 0.87 -11.7%
devManagerResponsive 4s 3.6s -455ms 0.3 -12.5%
devManagerHeaderVisible 608ms 559ms -49ms 0.1 -8.8%
devManagerIndexVisible 702ms 592ms -110ms -0.34 -18.6%
devStoryVisibleUncached 1.1s 960ms -214ms -0.11 -22.3%
devStoryVisible 647ms 591ms -56ms -0.21 -9.5%
devAutodocsVisible 502ms 482ms -20ms -0.34 -4.1%
devMDXVisible 548ms 488ms -60ms -0.13 -12.3%
buildManagerHeaderVisible 611ms 543ms -68ms -0.22 -12.5%
buildManagerIndexVisible 628ms 554ms -74ms -0.31 -13.4%
buildStoryVisible 613ms 538ms -75ms -0.27 -13.9%
buildAutodocsVisible 601ms 457ms -144ms -0.39 -31.5%
buildMDXVisible 493ms 413ms -80ms -0.51 -19.4%

Greptile Summary

Added support for Next.js 15 in Storybook's experimental Next.js Vite framework, with key updates to package dependencies, compatibility layers, and template stories.

  • Updated package.json to support Next.js 15 with peer dependencies ^14.1.0 || ^15.0.0 and updated vite-plugin-storybook-nextjs to canary version
  • Added async/await support in NextHeader.tsx and ServerActions.tsx for Next.js 15's asynchronous cookies/headers APIs
  • Added compatibility layer for draftMode in draft-mode.compat.ts to handle Next.js version differences
  • Improved TypeScript types across template stories for better type safety and maintainability
  • Added new sandbox template experimental-nextjs-vite/14-ts while updating default-ts for latest Next.js version

Copy link

nx-cloud bot commented Nov 18, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 6a1bbc4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

18 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -99,16 +99,16 @@
"@storybook/react": "workspace:*",
"@storybook/test": "workspace:*",
"styled-jsx": "5.1.6",
"vite-plugin-storybook-nextjs": "^1.0.11"
"vite-plugin-storybook-nextjs": "1.1.0--canary.27.f775ea2.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

style: using a canary version in production dependencies could be unstable - consider waiting for a stable release


// mock utilities/overrides (as of Next v14.2.0)
export { headers } from './headers';
export { cookies } from './cookies';

// passthrough mocks - keep original implementation but allow for spying
const draftMode = fn(originalHeaders.draftMode).mockName('draftMode');
const draftMode = fn(originalDraftMode ?? (headers as any).draftMode).mockName('draftMode');
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider adding type assertion for headers.draftMode to avoid using any

</p>
);
})}
{(await cookies()).getAll().map(({ name, value }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: potential race condition between getting cookies and rendering - cookies().getAll() is called on each render


export const RSC = async ({ label }: { label: string }) => <>RSC {label}</>;

export const Nested = async ({ children }: any) => <>Nested {children}</>;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: children prop uses 'any' type which loses type safety. Consider using PropsWithChildren or ReactNode type instead

@@ -16,13 +16,13 @@ export async function accessRoute() {
}

export async function logout() {
cookies().delete('user');
(await cookies()).delete('user');
Copy link
Contributor

Choose a reason for hiding this comment

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

style: check that cookie exists before attempting to delete it

revalidatePath('/');
redirect('/');
}

export async function login() {
cookies().set('user', 'storybookjs');
(await cookies()).set('user', 'storybookjs');
Copy link
Contributor

Choose a reason for hiding this comment

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

style: verify cookie is set successfully before proceeding with redirect

Comment on lines +211 to 213
'experimental-nextjs-vite/14-ts': {
name: 'Next.js Latest (Vite | TypeScript)',
script:
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: template name 'Next.js Latest' is misleading since this is specifically for Next.js 14

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Nov 18, 2024

Package Benchmarks

Commit: 6a1bbc4, ran on 19 November 2024 at 18:56:46 UTC

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

@storybook/core

Before After Difference
Dependency count 46 46 0
Self size 19.24 MB 19.08 MB 🎉 -169 KB 🎉
Dependency size 14.29 MB 14.29 MB 0 B
Bundle Size Analyzer Link Link

@storybook/experimental-nextjs-vite

Before After Difference
Dependency count 87 87 0
Self size 230 KB 231 KB 🚨 +161 B 🚨
Dependency size 31.03 MB 31.30 MB 🚨 +269 KB 🚨
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 47 47 0
Self size 22 KB 22 KB 0 B
Dependency size 33.54 MB 33.37 MB 🎉 -169 KB 🎉
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 48 48 0
Self size 1 KB 1 KB 0 B
Dependency size 33.56 MB 33.39 MB 🎉 -169 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 390 390 0
Self size 483 KB 483 KB 🎉 -282 B 🎉
Dependency size 74.60 MB 74.43 MB 🎉 -172 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 270 270 0
Self size 612 KB 612 KB 0 B
Dependency size 64.60 MB 64.43 MB 🎉 -169 KB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 105 105 0
Self size 1.11 MB 1.11 MB 🎉 -3 KB 🎉
Dependency size 42.54 MB 42.37 MB 🎉 -169 KB 🎉
Bundle Size Analyzer Link Link

@yannbf yannbf self-assigned this Nov 18, 2024
@yannbf yannbf force-pushed the yann/next-15-support-vite branch 2 times, most recently from 3521df0 to 81d586b Compare November 18, 2024 16:11
This reverts commit 8173350.
@yannbf yannbf added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Nov 20, 2024
@yannbf yannbf merged commit 9794e35 into next Nov 20, 2024
60 checks passed
@yannbf yannbf deleted the yann/next-15-support-vite branch November 20, 2024 09:01
yannbf added a commit that referenced this pull request Nov 20, 2024
Nextjs-Vite: Add Next.js 15 support
(cherry picked from commit 9794e35)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal feature request patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants