fix(nextjs-vite): add Next.js 16 internal modules to optimizeDeps#34774
fix(nextjs-vite): add Next.js 16 internal modules to optimizeDeps#34774jshaofa-ui wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThe Next.js-Vite preset module is refactored to define the ChangesNext.js-Vite Framework Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code/frameworks/nextjs-vite/src/preset.ts (1)
13-15: 💤 Low valueUnrelated refactoring: explicit file extensions.
These import changes are unrelated to the Next.js 16 dev-mode fix described in the PR objectives. While they align with the coding guideline to use explicit
.tsextensions, they broaden the PR scope unnecessarily. Consider isolating unrelated refactoring to separate PRs for cleaner history.As per coding guidelines, for TypeScript source in the repo, prefer explicit file extensions for relative code imports and exports.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@code/frameworks/nextjs-vite/src/preset.ts` around lines 13 - 15, The import changes in preset.ts (normalizePostCssConfig, FrameworkOptions, getNextjsVersion) introduce unrelated refactoring (adding explicit .ts extensions) that should not be mixed with the Next.js 16 dev-mode fix; revert those import edits so the PR only contains the intended bugfix, or move the extension changes into a separate cleanup PR. Locate the imports for normalizePostCssConfig, FrameworkOptions, and getNextjsVersion in preset.ts and restore their previous import specifiers (remove the explicit .ts extensions) or split the file changes into two commits/PRs so the refactor is isolated from the bugfix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@code/frameworks/nextjs-vite/src/preset.ts`:
- Around line 13-15: The import changes in preset.ts (normalizePostCssConfig,
FrameworkOptions, getNextjsVersion) introduce unrelated refactoring (adding
explicit .ts extensions) that should not be mixed with the Next.js 16 dev-mode
fix; revert those import edits so the PR only contains the intended bugfix, or
move the extension changes into a separate cleanup PR. Locate the imports for
normalizePostCssConfig, FrameworkOptions, and getNextjsVersion in preset.ts and
restore their previous import specifiers (remove the explicit .ts extensions) or
split the file changes into two commits/PRs so the refactor is isolated from the
bugfix.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9a02c733-e389-490f-8906-628ebe0e9c84
📒 Files selected for processing (1)
code/frameworks/nextjs-vite/src/preset.ts
|
Thanks for the CodeRabbit review! The import extension changes in The core fix is the Could a maintainer review this PR? The fix addresses the |
Add next/navigation and related Next.js 16 internal modules to the Vite optimizeDeps configuration. This fixes missing exports like ServerInsertedHTMLContext and RedirectStatusCode during Vite dev mode pre-bundling. The issue occurs because Vite's esbuild pre-bundler doesn't correctly resolve Next.js 16's internal re-export chains. Adding these modules to optimizeDeps forces Vite to pre-bundle them correctly. Fixes storybookjs#34688
2c8c5db to
32932a0
Compare
Co-authored-by: Valentin Palkovic <dev@valentinpalkovic.dev>
|
Thanks for the fix, @jshaofa-ui! After review, the root cause lives in the I've ported your change to that repository with a changeset: storybookjs/vite-plugin-storybook-nextjs#NEW_PR (link to follow). Once it's released, the fix flows into Storybook automatically. Closing this in favor of that PR — appreciate the contribution and the clear root-cause writeup in #34688! |
|
Follow-up: the replacement PR is storybookjs/vite-plugin-storybook-nextjs#123 — storybookjs/vite-plugin-storybook-nextjs#123 (your change ported there with a changeset, credited to you). |
Summary
Fixes the
ServerInsertedHTMLContextandRedirectStatusCodemissing exports error when using Storybook with Next.js 16 + Vite 8 in dev mode.Problem
Vite 8's esbuild pre-bundler doesn't correctly resolve Next.js 16's internal re-export chains from
next/navigation. This causes aSyntaxErrorduring development:The issue only occurs in dev mode (esbuild pre-bundling) — production builds work fine because Rollup handles CJS/ESM interop differently.
Root Cause
next/navigationand related Next.js internal modules are not included in Storybook'soptimizeViteDepsconfiguration, so Vite's pre-bundler doesn't process them correctly.Fix
Added
next/navigationandnext/dist/client/components/redirect-errorto theoptimizeViteDepsarray incode/frameworks/nextjs-vite/src/preset.ts.Changes
code/frameworks/nextjs-vite/src/preset.tsoptimizeViteDepsTesting
Fixes #34688
Summary by CodeRabbit