fix: pre-bundle Next.js 16 navigation/redirect-error for Vite dev mode#123
Merged
Conversation
Next.js 16 ships internal re-export chains that Vite's esbuild pre-bundler fails to resolve in dev mode, causing missing exports like ServerInsertedHTMLContext and RedirectStatusCode. Add next/navigation and next/dist/client/components/redirect-error to optimizeDeps.include for Next.js 16+ so Vite pre-bundles them correctly. See: storybookjs/storybook#34688
Preview ReleasePublished Packages:
Templates: |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
next/navigationandnext/dist/client/components/redirect-errortooptimizeDeps.includefor Next.js 16+.Why
Next.js 16 ships internal re-export chains that Vite's esbuild pre-bundler fails to resolve in dev mode. This surfaces as missing exports such as
ServerInsertedHTMLContextandRedirectStatusCodewhen running Storybook with@storybook/nextjs-viteon Next.js 16. Forcing these modules to be pre-bundled fixes the resolution.The entries are gated behind the existing
isNext16orNewercheck so Next.js < 16 setups are unaffected.Context
This supersedes storybookjs/storybook#34774, which proposed the same fix in Storybook's
@storybook/nextjs-vitepreset. The actualoptimizeDepsconfig lives here in the Vite plugin, so this is the correct single source of truth. Once released, the fix flows into Storybook automatically.Fixes the root cause described in storybookjs/storybook#34688.
Original contribution by @jshaofa-ui.
Checklist
patch)pnpm buildpassespnpm checkpasses🤖 Generated with Claude Code