-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Describe the bug
As of Next.js 15.2, we can use the unstable_ViewTransition component from react@experimental by enabling the experimental.viewTransition flag in next.config.js. You can find more details in the Next.js documentation.
However, when using @storybook/nextjs-vite, any attempt to import { unstable_ViewTransition } from "react"
within a story results in unstable_ViewTransition being undefined. This prevents the story from rendering.
Steps to reproduce the behavior
- Enable viewTransition in next.config.mjs:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
viewTransition: true,
},
};
export default nextConfig;
- Create a component that imports unstable_ViewTransition:
import { unstable_ViewTransition as ViewTransition } from "react";
// This logs the React component object when running `next dev`.
// This logs `undefined` when running `storybook dev` or `vitest`.
console.log(ViewTransition);
Expected behavior
unstable_ViewTransition should be correctly imported and available for use within Storybook stories, just as it is in a standard Next.js application when the experimental.viewTransition flag is enabled.
Screenshots and/or logs
If applicable, add screenshots and/or logs to help explain your problem.
Environment
- Next.js: 15.3.4
- vite-plugin-storybook-nextjs: 2.0.2
Additional context
It seems the Next.js bundler has specific logic to alias react to next/dist/compiled/react-experimental when the viewTransition flag is active. You can see this implementation in the Next.js source code here:
It appears that similar logic has not yet been implemented in vite-plugin-storybook-nextjs. This likely causes Vite to resolve the standard React module instead of the experimental one that includes ViewTransition.