Skip to content

NextJS: Import next/dist with .js-extension for ESM compat#33380

Merged
ndelangen merged 1 commit into
storybookjs:nextfrom
lab-yue:fix-next-package-esm-compat
Dec 29, 2025
Merged

NextJS: Import next/dist with .js-extension for ESM compat#33380
ndelangen merged 1 commit into
storybookjs:nextfrom
lab-yue:fix-next-package-esm-compat

Conversation

@yue4u
Copy link
Copy Markdown
Contributor

@yue4u yue4u commented Dec 17, 2025

Closes #33379

What I did

fix imports with .js extensions

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

  1. Build packages locally
  2. Link built package to https://github.com/lab-yue/reproduction-portable-stories-next
  3. Tests run successfully

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 publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • Exported a cookies helper from the Next.js integration layer.
  • Chores

    • Normalized Next.js module specifiers to explicit .js entry points across integration layers to align with current module resolution. No runtime behavior or public API changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@yue4u yue4u changed the title fix: import with js extension for ESM compat fix: import next/dist code with js extension for ESM compat Dec 17, 2025
@ndelangen ndelangen self-assigned this Dec 22, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 22, 2025

📝 Walkthrough

Walkthrough

Module specifiers for internal Next.js imports/exports were changed to include explicit .js (or .../index.js) file extensions across Next.js integration files; no runtime logic, control flow, or public API signatures were modified.

Changes

Cohort / File(s) Summary
Headers export mocks
code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts, code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts, code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts, code/frameworks/nextjs/src/export-mocks/headers/cookies.ts, code/frameworks/nextjs/src/export-mocks/headers/headers.ts, code/frameworks/nextjs/src/export-mocks/headers/index.ts
Updated import/re-export specifiers to explicit .js (and .../index.js) paths; added cookies export in nextjs-vite index. No logic changes.
Navigation & router export mocks
code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts, code/frameworks/nextjs-vite/src/export-mocks/router/index.ts, code/frameworks/nextjs/src/export-mocks/navigation/index.ts, code/frameworks/nextjs/src/export-mocks/router/index.ts
Replaced bare Next.js specifiers with .js-suffixed module paths for navigation/router imports and re-exports.
Cache export mock
code/frameworks/nextjs/src/export-mocks/cache/index.ts
Added .js extensions to unstable_cache and unstable_noStore import specifiers.
Head manager
code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx, code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
Replaced internal Next.js imports with .js-suffixed paths (head manager and head-manager-context).
Routing components
code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx, code/frameworks/nextjs-vite/src/routing/decorator.tsx, code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx, code/frameworks/nextjs/src/routing/app-router-provider.tsx, code/frameworks/nextjs/src/routing/decorator.tsx, code/frameworks/nextjs/src/routing/page-router-provider.tsx
Updated routing-related imports to use .js extensions (segment, context, redirect-boundary, etc.).
Preview
code/frameworks/nextjs-vite/src/preview.tsx, code/frameworks/nextjs/src/preview.tsx
Switched isNextRouterError import to .js module specifier.
Compatibility
code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
Re-export source for draftMode updated to .js module specifier.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Highly repetitive change (append .js / use index.js) across many files.
  • Areas to spot-check:
    • Header mocks (cookies export addition in nextjs-vite index)
    • Consistency between .js paths and any tooling/packager expectations
    • Any places where .js was added to a package entry that may be directory-only (ensure paths resolve)

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1634bdc and f2cabdc.

📒 Files selected for processing (22)
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
🚧 Files skipped from review as they are similar to previous changes (16)
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
🧠 Learnings (7)
📓 Common learnings
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32594
File: code/core/src/components/components/Popover/WithPopover.tsx:7-9
Timestamp: 2025-10-01T15:24:01.060Z
Learning: In the Storybook repository, "react-aria-components/patched-dist/*" (e.g., "react-aria-components/patched-dist/Dialog", "react-aria-components/patched-dist/Popover", "react-aria-components/patched-dist/Tooltip") are valid import paths created by a patch applied to the react-aria-components package. These imports should not be flagged as broken or invalid until a maintainer explicitly states they are no longer acceptable.
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to **/*.{js,jsx,json,html,ts,tsx,mjs} : Use ESLint and Prettier configurations that are enforced in the codebase
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx,js,jsx} : Mock external dependencies using vi.mock() for file system, loggers, and other external dependencies in tests

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock all required dependencies that the test subject uses

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
📚 Learning: 2025-09-24T09:39:39.233Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.

Applied to files:

  • code/frameworks/nextjs/src/preview.tsx
📚 Learning: 2025-11-05T09:38:47.712Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.

Applied to files:

  • code/frameworks/nextjs/src/preview.tsx
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : Use client-side logger from 'storybook/internal/client-logger' for browser code

Applied to files:

  • code/frameworks/nextjs/src/preview.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: normal
🔇 Additional comments (6)
code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts (1)

8-8: ESM compatibility fix is correct.

Adding the explicit /index.js extension is necessary for ESM module resolution in vitest and Node.js. The import path next/dist/compiled/@edge-runtime/cookies/index.js enables proper ESM resolution when running portable story tests. This change aligns with documented vitest/ESM requirements where file extensions are required for proper module resolution, and is consistently applied across both the nextjs-vite and nextjs frameworks.

code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx (1)

4-5: LGTM! Module paths updated for ESM compatibility.

The explicit .js extensions correctly resolve Next.js internal modules for ESM environments. The comment on line 3-5 notes the singleton requirement, and these changes maintain that behavior while fixing resolution.

code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts (1)

1-2: LGTM! Re-export path updated consistently.

The .js extension on the re-export aligns with the broader PR changes to Next.js internal module paths. The comment indicates this is for Next.js 14 compatibility.

code/frameworks/nextjs/src/export-mocks/headers/index.ts (1)

1-5: LGTM! Import and re-export paths updated consistently.

Both the import and re-export from next/dist/server/request/headers now include the .js extension, ensuring ESM compatibility while maintaining the mock utilities and overrides.

code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx (1)

15-21: LGTM! ESM-compatible module paths added.

ESM imports require explicit file extensions per the ECMAScript spec. The explicit .js extensions on Next.js internal module imports align with the PR objective to fix ESM resolution issues for Next.js 14 and 15+. No logic changes, only module specifier updates that enable proper bundler resolution with Vite.

code/frameworks/nextjs/src/preview.tsx (1)

15-15: LGTM! ESM compatibility fix applied correctly.

The addition of the .js extension to the Next.js internal module import aligns with the established pattern across the codebase (42 similar imports consistently use .js extensions) and addresses ESM module resolution requirements. The imported isNextRouterError function is properly used in error handling contexts (lines 44, 51, 85).


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d9a2a5 and 1634bdc.

📒 Files selected for processing (22)
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
🧠 Learnings (25)
📓 Common learnings
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32594
File: code/core/src/components/components/Popover/WithPopover.tsx:7-9
Timestamp: 2025-10-01T15:24:01.060Z
Learning: In the Storybook repository, "react-aria-components/patched-dist/*" (e.g., "react-aria-components/patched-dist/Dialog", "react-aria-components/patched-dist/Popover", "react-aria-components/patched-dist/Tooltip") are valid import paths created by a patch applied to the react-aria-components package. These imports should not be flagged as broken or invalid until a maintainer explicitly states they are no longer acceptable.
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to **/*.{js,jsx,json,html,ts,tsx,mjs} : Use ESLint and Prettier configurations that are enforced in the codebase
📚 Learning: 2025-09-24T09:39:39.233Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.

Applied to files:

  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-05T09:38:47.712Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.

Applied to files:

  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : Use client-side logger from 'storybook/internal/client-logger' for browser code

Applied to files:

  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Follow existing patterns and conventions in the Storybook codebase

Applied to files:

  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
📚 Learning: 2025-11-05T09:37:25.920Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/tooltip/WithTooltip.tsx:54-96
Timestamp: 2025-11-05T09:37:25.920Z
Learning: Repo: storybookjs/storybook — In code/core/src/components/components/tooltip/WithTooltip.tsx, the legacy WithTooltip implementation is intentionally reintroduced for backward compatibility and is deprecated; maintainers (per Sidnioulz) do not want maintenance or improvements on it. Prefer WithTooltipNew/Popover; avoid suggesting changes to WithTooltip.* going forward.

Applied to files:

  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx,js,jsx} : Mock external dependencies using vi.mock() for file system, loggers, and other external dependencies in tests

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock implementations should match the expected return type of the original function

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock all required dependencies that the test subject uses

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mocking only a subset of required dependencies in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid inline mock implementations within test cases in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Keep mock implementations simple and focused in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid direct function mocking without `vi.mocked()` in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Group related mocks together in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Document complex mock behaviors in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock all required properties and methods that the test subject uses in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Use `vi.mock()` with the `spy: true` option for all package and file mocks in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : Use server-side logger from 'storybook/internal/node-logger' for Node.js code

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mock implementations outside of `beforeEach` blocks in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx,js,jsx} : Write meaningful unit tests that actually import and call the functions being tested

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
📚 Learning: 2025-11-24T17:49:31.838Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursorrules:0-0
Timestamp: 2025-11-24T17:49:31.838Z
Learning: Applies to **/*.{test,spec}.{ts,tsx} : Follow the spy mocking rules defined in `.cursor/rules/spy-mocking.mdc` for consistent mocking patterns with Vitest

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Implement mock behaviors in `beforeEach` blocks in Vitest tests

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Use type-safe mocking with `vi.mocked()` in Vitest tests

Applied to files:

  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
📚 Learning: 2025-10-01T15:24:01.060Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32594
File: code/core/src/components/components/Popover/WithPopover.tsx:7-9
Timestamp: 2025-10-01T15:24:01.060Z
Learning: In the Storybook repository, "react-aria-components/patched-dist/*" (e.g., "react-aria-components/patched-dist/Dialog", "react-aria-components/patched-dist/Popover", "react-aria-components/patched-dist/Tooltip") are valid import paths created by a patch applied to the react-aria-components package. These imports should not be flagged as broken or invalid until a maintainer explicitly states they are no longer acceptable.

Applied to files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: normal
🔇 Additional comments (23)
code/frameworks/nextjs-vite/src/routing/decorator.tsx (2)

5-5: LGTM: ESM-compatible import path.

The addition of the .js extension aligns with ES module resolution requirements and resolves the module resolution issue in vitest environments.


15-15: LGTM: Consistent ESM module paths.

The .js extensions on Next.js shared runtime imports ensure proper module resolution in ESM environments.

Also applies to: 20-21

code/frameworks/nextjs-vite/src/preview.tsx (1)

14-14: LGTM: ESM path for error utility.

The .js extension on the isNextRouterError import ensures the error handling logic can resolve Next.js internals correctly in ESM mode.

code/frameworks/nextjs/src/routing/decorator.tsx (1)

5-5: LGTM: Consistent ESM import path.

Matches the equivalent change in the nextjs-vite framework, ensuring both framework variants support ESM module resolution.

code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx (1)

11-11: LGTM: Page router ESM compatibility.

The .js extension on the RouterContext import ensures the page router provider resolves correctly in ESM environments.

code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts (1)

1-1: LGTM: Headers adapter ESM path.

The .js extension on the HeadersAdapter import ensures the mock implementation can resolve Next.js server adapters in ESM mode.

code/frameworks/nextjs/src/preview.tsx (1)

15-15: LGTM: Consistent across framework variants.

Matches the equivalent ESM path update in nextjs-vite, ensuring error handling works in both framework implementations.

code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx (1)

4-5: LGTM: Head manager ESM imports.

Both head-manager related imports now use explicit .js extensions for proper ESM resolution.

code/frameworks/nextjs/src/export-mocks/router/index.ts (1)

3-3: LGTM - Consistent ESM import and re-export paths.

Both the import and re-export statements are correctly updated with .js extensions, ensuring consistent module resolution.

Also applies to: 111-111

code/frameworks/nextjs/src/export-mocks/headers/headers.ts (1)

1-1: LGTM - ESM-compatible import for HeadersAdapter.

The import path correctly includes the .js extension for ESM compatibility.

code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts (1)

2-2: LGTM - ESM-compatible re-export path.

The .js extension addition maintains Next.js 14 compatibility while ensuring proper ESM resolution.

code/frameworks/nextjs-vite/src/export-mocks/router/index.ts (1)

3-3: LGTM - Consistent ESM paths across frameworks.

The import and re-export are correctly updated to match the non-Vite framework variant, ensuring consistent behavior.

Also applies to: 111-111

code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx (1)

4-5: LGTM - ESM-compatible imports for head manager.

Both import paths correctly include .js extensions for ESM compatibility without affecting the component's functionality.

code/frameworks/nextjs/src/routing/app-router-provider.tsx (1)

15-15: LGTM - ESM-compatible imports for app router contexts.

All three import paths (app-router-context, hooks-client-context, and segment) correctly include .js extensions for ESM compatibility.

Also applies to: 20-21

code/frameworks/nextjs/src/routing/page-router-provider.tsx (1)

11-11: Add .js extension for ESM/vitest module resolution.

The .js extension is required for proper ESM module resolution in vitest environments, following Node.js ESM specification requirements that demand explicit file extensions.

import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime.js';
⛔ Skipped due to learnings
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mocking only a subset of required dependencies in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursorrules:0-0
Timestamp: 2025-11-24T17:49:31.838Z
Learning: Applies to **/*.{test,spec}.{ts,tsx} : Test files should follow the naming pattern `*.test.ts`, `*.test.tsx`, `*.spec.ts`, or `*.spec.tsx`
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Document complex mock behaviors in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid direct function mocking without `vi.mocked()` in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid inline mock implementations within test cases in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Use `vi.mock()` with the `spy: true` option for all package and file mocks in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Implement mock behaviors in `beforeEach` blocks in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mocking without the `spy: true` option in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Keep mock implementations simple and focused in Vitest tests
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Group related mocks together in Vitest tests
code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts (1)

3-5: Code snippet does not match actual implementation - missing .js extensions in imports.

The imports in the code snippet shown at lines 3-5 incorrectly claim to include .js extensions ('next/dist/client/components/navigation.js', etc.), but the actual code does not contain these extensions. The imports should be reviewed against the actual code state without the .js suffix. While ESM-style imports with .js extensions are valid and increasingly recommended for ESM resolution, any approval should be based on the actual code present, not speculative imports.

Likely an incorrect or invalid review comment.

code/frameworks/nextjs/src/export-mocks/headers/cookies.ts (1)

8-8: Consistent with nextjs-vite variant.

The /index.js path change is consistent with the nextjs-vite framework variant and correctly targets the compiled edge-runtime cookies index module.

code/frameworks/nextjs/src/export-mocks/headers/index.ts (2)

1-1: Headers import paths updated correctly.

The .js extensions added to the headers module import and re-export are consistent with the ESM compatibility objective.

Also applies to: 5-5


19-19: Remove the suggestion to add .js extension to the require() call.

The file correctly uses each module system according to its specification: ESM imports include .js extensions (as required), while CommonJS require() omits them (as is standard practice). Node.js automatically resolves .js files when no extension is specified in CommonJS. The webpack alias comment explains that omitting .js in the require() call is intentional to allow proper version-specific module resolution. This is not an inconsistency but proper usage of both module systems.

code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts (1)

8-8: The /index.js path for compiled edge-runtime cookies is correct.

This import follows the established pattern throughout the codebase for importing from compiled package directories in Next.js. The identical import already exists in the corresponding nextjs framework code, and all similar compiled package imports use the /index.js convention for ESM module resolution.

code/frameworks/nextjs/src/export-mocks/navigation/index.ts (1)

3-5: The .js extension imports for Next.js internal modules are correct and required for ESM compatibility.

These paths exist in Next.js distribution and the .js extensions align with ESM specifications. No changes needed.

code/frameworks/nextjs/src/export-mocks/cache/index.ts (1)

1-2: Use public Next.js imports instead of internal module paths.

Import unstable_cache and unstable_noStore from 'next/cache', not from internal dist paths. The imports should be:

import { unstable_cache } from 'next/cache';
import { unstable_noStore } from 'next/cache';

The @storybook/nextjs/cache.mock module provides mocked implementations of the next/cache module's exports if Storybook-specific mocks are needed.

Likely an incorrect or invalid review comment.

code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx (1)

15-15: ESM-compatible import paths with .js extensions.

The updates correctly add .js extensions to Next.js internal module imports, which aligns with the PR objective of improving ESM compatibility for portable story tests using vitest. Type-only imports (line 10) are appropriately excluded from this update since they don't affect runtime resolution.

Please verify that these Next.js module paths are valid in the Next.js versions supported by Storybook:

  • next/dist/shared/lib/app-router-context.shared-runtime.js
  • next/dist/shared/lib/hooks-client-context.shared-runtime.js
  • next/dist/shared/lib/segment.js

You can verify by checking if these paths exist in the Next.js repository for the supported version range, or by confirming the tests pass after the change.

Also applies to: 20-21

Comment on lines +1 to +2
import { draftMode as originalDraftMode } from 'next/dist/server/request/draft-mode.js';
import * as headers from 'next/dist/server/request/headers.js';
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.

⚠️ Potential issue | 🔴 Critical

Using internal Next.js implementation paths will cause module resolution failures.

The Next.js documentation specifies draft mode should be imported from 'next/headers', not from internal 'next/dist/server/request/draft-mode' paths which don't exist. This is causing active build failures in Storybook v10. Internal paths in next/dist/* are implementation details with no stability guarantees and should not be used for exports or mocks.

🤖 Prompt for AI Agents
In code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts lines 1-2, the
file imports from internal Next.js paths ('next/dist/server/request/...') which
breaks module resolution; replace those imports with the public Next.js
entrypoint by importing draftMode and headers from 'next/headers' (no /dist path
or .js extension), adjust local variable names to match (e.g., use draftMode
directly instead of originalDraftMode) and update any subsequent exports or
usages to re-export or mock the public API shapes so Storybook uses stable
public exports.

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented Dec 22, 2025

Package Benchmarks

Commit: f2cabdc, ran on 24 December 2025 at 19:17:25 UTC

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

@storybook/addon-docs

Before After Difference
Dependency count 18 18 0
Self size 1.64 MB 1.79 MB 🚨 +153 KB 🚨
Dependency size 9.25 MB 9.25 MB 🚨 +12 B 🚨
Bundle Size Analyzer Link Link

@storybook/builder-vite

Before After Difference
Dependency count 17 17 0
Self size 125 KB 325 KB 🚨 +200 KB 🚨
Dependency size 2.00 MB 2.00 MB 🚨 +12 B 🚨
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 49 49 0
Self size 20.19 MB 20.52 MB 🚨 +332 KB 🚨
Dependency size 16.52 MB 16.52 MB 0 B
Bundle Size Analyzer Link Link

@storybook/html-vite

Before After Difference
Dependency count 20 20 0
Self size 22 KB 22 KB 🎉 -1 B 🎉
Dependency size 2.16 MB 2.36 MB 🚨 +200 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 127 127 0
Self size 1.12 MB 1.12 MB 🚨 +197 B 🚨
Dependency size 21.78 MB 21.98 MB 🚨 +199 KB 🚨
Bundle Size Analyzer Link Link

@storybook/preact-vite

Before After Difference
Dependency count 20 20 0
Self size 13 KB 13 KB 🎉 -1 B 🎉
Dependency size 2.15 MB 2.35 MB 🚨 +200 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 159 159 0
Self size 30 KB 30 KB 🎉 -1 B 🎉
Dependency size 22.96 MB 23.16 MB 🚨 +199 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 117 117 0
Self size 35 KB 35 KB 🚨 +17 B 🚨
Dependency size 19.58 MB 19.78 MB 🚨 +199 KB 🚨
Bundle Size Analyzer Link Link

@storybook/svelte-vite

Before After Difference
Dependency count 24 24 0
Self size 55 KB 56 KB 🚨 +23 B 🚨
Dependency size 26.82 MB 27.02 MB 🚨 +200 KB 🚨
Bundle Size Analyzer Link Link

@storybook/sveltekit

Before After Difference
Dependency count 25 25 0
Self size 56 KB 56 KB 🎉 -49 B 🎉
Dependency size 26.88 MB 27.08 MB 🚨 +200 KB 🚨
Bundle Size Analyzer Link Link

@storybook/vue3-vite

Before After Difference
Dependency count 114 114 0
Self size 35 KB 35 KB 🎉 -1 B 🎉
Dependency size 43.98 MB 44.18 MB 🚨 +200 KB 🚨
Bundle Size Analyzer Link Link

@storybook/web-components-vite

Before After Difference
Dependency count 21 21 0
Self size 19 KB 19 KB 🚨 +11 B 🚨
Dependency size 2.19 MB 2.39 MB 🚨 +200 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 775 KB 775 KB 🎉 -236 B 🎉
Dependency size 67.24 MB 67.58 MB 🚨 +332 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 176 176 0
Self size 30 KB 30 KB 🎉 -36 B 🎉
Dependency size 65.82 MB 66.15 MB 🚨 +332 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 50 50 0
Self size 999 KB 999 KB 0 B
Dependency size 36.71 MB 37.04 MB 🚨 +332 KB 🚨
Bundle Size Analyzer node node

@yue4u yue4u force-pushed the fix-next-package-esm-compat branch from 1634bdc to f2cabdc Compare December 22, 2025 15:18
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/frameworks/nextjs/src/export-mocks/headers/index.ts (1)

16-23: Add .js extension to the require() call for consistency with ES module imports in this file.

Line 19 uses require('next/dist/server/request/draft-mode') without a file extension, while the ES module imports on lines 1 and 5 explicitly use .js extensions: 'next/dist/server/request/headers.js'. This inconsistency should be resolved by adding the extension: require('next/dist/server/request/draft-mode.js') to match the established pattern in the file and codebase.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1634bdc and f2cabdc.

📒 Files selected for processing (22)
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
🚧 Files skipped from review as they are similar to previous changes (16)
  • code/frameworks/nextjs/src/export-mocks/cache/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs-vite/src/preview.tsx
  • code/frameworks/nextjs-vite/src/routing/decorator.tsx
  • code/frameworks/nextjs/src/export-mocks/navigation/index.ts
  • code/frameworks/nextjs/src/export-mocks/router/index.ts
  • code/frameworks/nextjs/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs/src/routing/page-router-provider.tsx
  • code/frameworks/nextjs/src/routing/decorator.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs/src/export-mocks/headers/headers.ts
  • code/frameworks/nextjs-vite/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/export-mocks/navigation/index.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
  • code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx
  • code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts
  • code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx
  • code/frameworks/nextjs/src/preview.tsx
🧠 Learnings (7)
📓 Common learnings
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32594
File: code/core/src/components/components/Popover/WithPopover.tsx:7-9
Timestamp: 2025-10-01T15:24:01.060Z
Learning: In the Storybook repository, "react-aria-components/patched-dist/*" (e.g., "react-aria-components/patched-dist/Dialog", "react-aria-components/patched-dist/Popover", "react-aria-components/patched-dist/Tooltip") are valid import paths created by a patch applied to the react-aria-components package. These imports should not be flagged as broken or invalid until a maintainer explicitly states they are no longer acceptable.
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to **/*.{js,jsx,json,html,ts,tsx,mjs} : Use ESLint and Prettier configurations that are enforced in the codebase
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx,js,jsx} : Mock external dependencies using vi.mock() for file system, loggers, and other external dependencies in tests

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock all required dependencies that the test subject uses

Applied to files:

  • code/frameworks/nextjs/src/export-mocks/headers/index.ts
📚 Learning: 2025-09-24T09:39:39.233Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.

Applied to files:

  • code/frameworks/nextjs/src/preview.tsx
📚 Learning: 2025-11-05T09:38:47.712Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.

Applied to files:

  • code/frameworks/nextjs/src/preview.tsx
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : Use client-side logger from 'storybook/internal/client-logger' for browser code

Applied to files:

  • code/frameworks/nextjs/src/preview.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: normal
🔇 Additional comments (6)
code/frameworks/nextjs-vite/src/export-mocks/headers/cookies.ts (1)

8-8: ESM compatibility fix is correct.

Adding the explicit /index.js extension is necessary for ESM module resolution in vitest and Node.js. The import path next/dist/compiled/@edge-runtime/cookies/index.js enables proper ESM resolution when running portable story tests. This change aligns with documented vitest/ESM requirements where file extensions are required for proper module resolution, and is consistently applied across both the nextjs-vite and nextjs frameworks.

code/frameworks/nextjs-vite/src/head-manager/head-manager-provider.tsx (1)

4-5: LGTM! Module paths updated for ESM compatibility.

The explicit .js extensions correctly resolve Next.js internal modules for ESM environments. The comment on line 3-5 notes the singleton requirement, and these changes maintain that behavior while fixing resolution.

code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts (1)

1-2: LGTM! Re-export path updated consistently.

The .js extension on the re-export aligns with the broader PR changes to Next.js internal module paths. The comment indicates this is for Next.js 14 compatibility.

code/frameworks/nextjs/src/export-mocks/headers/index.ts (1)

1-5: LGTM! Import and re-export paths updated consistently.

Both the import and re-export from next/dist/server/request/headers now include the .js extension, ensuring ESM compatibility while maintaining the mock utilities and overrides.

code/frameworks/nextjs-vite/src/routing/app-router-provider.tsx (1)

15-21: LGTM! ESM-compatible module paths added.

ESM imports require explicit file extensions per the ECMAScript spec. The explicit .js extensions on Next.js internal module imports align with the PR objective to fix ESM resolution issues for Next.js 14 and 15+. No logic changes, only module specifier updates that enable proper bundler resolution with Vite.

code/frameworks/nextjs/src/preview.tsx (1)

15-15: LGTM! ESM compatibility fix applied correctly.

The addition of the .js extension to the Next.js internal module import aligns with the established pattern across the codebase (42 similar imports consistently use .js extensions) and addresses ESM module resolution requirements. The imported isNextRouterError function is properly used in error handling contexts (lines 44, 51, 85).

@yue4u
Copy link
Copy Markdown
Contributor Author

yue4u commented Dec 22, 2025

@ndelangen ndelangen added the esm label Dec 24, 2025
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Dec 24, 2025

View your CI Pipeline Execution ↗ for commit f2cabdc


☁️ Nx Cloud last updated this comment at 2025-12-24 13:09:01 UTC

@ndelangen ndelangen changed the title fix: import next/dist code with js extension for ESM compat NextJS: Import next/dist with .js-extension for ESM compat Dec 24, 2025
@ndelangen
Copy link
Copy Markdown
Member

I've looked at the size diff repostings, and I think there's some malfunction there, the size increases do not make sense with this change, I suspect there's some cache, possibly due to this PR being from a fork?

Something to look into for sure.

@ndelangen ndelangen merged commit 0e92e0c into storybookjs:next Dec 29, 2025
60 of 67 checks passed
@ndelangen
Copy link
Copy Markdown
Member

Thank you @yue4u !

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: portable story tests are broken due to next/dist imports without .js extension

2 participants