Skip to content

fix: pre-bundle Next.js 16 navigation/redirect-error for Vite dev mode#123

Merged
valentinpalkovic merged 1 commit into
mainfrom
fix/nextjs16-optimize-deps
May 19, 2026
Merged

fix: pre-bundle Next.js 16 navigation/redirect-error for Vite dev mode#123
valentinpalkovic merged 1 commit into
mainfrom
fix/nextjs16-optimize-deps

Conversation

@valentinpalkovic

Copy link
Copy Markdown
Contributor

What

Adds next/navigation and next/dist/client/components/redirect-error to optimizeDeps.include for 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 ServerInsertedHTMLContext and RedirectStatusCode when running Storybook with @storybook/nextjs-vite on Next.js 16. Forcing these modules to be pre-bundled fixes the resolution.

The entries are gated behind the existing isNext16orNewer check so Next.js < 16 setups are unaffected.

Context

This supersedes storybookjs/storybook#34774, which proposed the same fix in Storybook's @storybook/nextjs-vite preset. The actual optimizeDeps config 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

  • Changeset added (patch)
  • pnpm build passes
  • pnpm check passes

🤖 Generated with Claude Code

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
@github-actions

Copy link
Copy Markdown

Preview Release

Published Packages:

Templates:

View Commit

@valentinpalkovic valentinpalkovic merged commit a2a5ecd into main May 19, 2026
7 checks passed
@storybook-app-bot storybook-app-bot Bot mentioned this pull request May 19, 2026
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.

1 participant