-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Using appDirectory in preview.ts causes reactdom.preload error with Next.js framework #23661
Comments
@terrymun Hi, this seems like a bug introduced by I tested that it works if I downgrade nextjs to The problematic |
Thanks for digging into the changes that caused it @sookmax. We have implemented an interim fix for this: which is to simply shim export const config: StorybookConfig = {
// Your config goes here...
// Webpack config to define custom alias for next/image
webpackFinal: async (config) => {
if (config.resolve) {
config.resolve = {
...config.resolve,
alias: {
...config.resolve.alias,
/*
* NOTE: The next-image-shim manually disables the `priority` prop due to a bug with storybook
* https://github.com/storybookjs/storybook/issues/23661
* TODO: Remove this shim once the issue has been resolved
*/
'next/image': path.resolve(__dirname, 'next-image-shim.js'),
},
};
}
},
}; The known solution of using // NOTE: Import from node_modules directly otherwise webpack will enter a recursive loop when aliasing next/image
// eslint-disable-next-line no-restricted-imports
import Image from '../../../node_modules/next/image';
/*
* NOTE: The next-image-shim manually disables the `priority` prop due to a bug with storybook
* https://github.com/storybookjs/storybook/issues/23661
* TODO: Remove this shim once the issue has been resolved
*/
const NextImage = (props) => <Image {...props} unoptimized priority={false} />;
export default NextImage; I hope this will be helpful to whoever that comes across this issue :) |
Warning
|
…#53443) ### What? `ReactDOM.preload` is available in `react-dom@experimental` builds. If it's not available, we should fall back to `Head`+`link` ### Why? Since `ReactDOM.preload` is only available in `react-dom@experimental` builds, certain environments (like Jest or [Storybook](storybookjs/storybook#23661)) might have a version of `react-dom` installed that won't work with `preload()` ### How? Closes NEXT-1482 Fixes #53272 See also: storybookjs/storybook#23661 Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
Hi, this should not be the problem anymore, since vercel/next.js#53443 was merged! Cheers! |
Describe the bug
When using the image component from
next/image
, adding thepriority
flag will cause storybook stories to fail to render if the following conditions are met:@storybook/nextjs
frameworkpreview.ts
is setup to support Next.js app router as per guide here: https://storybook.js.org/recipes/next#configuring-nextnavigationDrilling down further, it seems that it is the addition of
appDirectory: true
that is causing the failure:If I remove the
appDirectory: true
setting, then all is good:However, I cannot remove this configuration in my production storybook as any components that are using
useRouter
fromnext/navigation
will no longer render.To Reproduce
A simple GitHub repo to reproduce this issue is available here: https://github.com/terrymun/storybook-nextjs-image-with-priority
An alternative way to reproduce this is to add the following lines to the
preview.js
(orpreview.ts
) file on a Storybook that is configured to work with Next.js:System
Additional context
No response
The text was updated successfully, but these errors were encountered: