-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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]: Next.js 13 - Broken next/link styles due to missing html attributes on <a> #19813
Comments
As a workaround, I added this to Object.defineProperty(Link, 'default', {
configurable: true,
value: (props) => <OriginalLink {...props}><a {...props}>{props.children}</a></OriginalLink>,
}) |
I can confirm that this is an issue, there are multiple issues with the |
Also confirmed here, this was driving me crazy. Tested the "mappings" functionality to pass JSX as options as well that I saw referenced somewhere and the problem still persisted. If anything other than a string/text node is passed it fails to render the anchor. There doesn't seem to be any useful console output other than a warning about the react 17/18 root API from the storybook manager. next 13.0.3 |
@muhammad-saleh 's fix worked for me THANKS! - the full fix I needed: // .storybook/preview.js
import * as NextLink from 'next/link';
const OriginalLink = NextLink.default;
Object.defineProperty(NextLink, 'default', {
configurable: true,
value: (props) => <OriginalLink {...props}><a {...props}>{props.children}</a></OriginalLink>,
}) |
I got Next 13 Link working on SB by setting in the .env file // .storybook/main.js
webpackFinal: async (config) => {
(...)
config.plugins.push(
new webpack.DefinePlugin({
'process.env.__NEXT_NEW_LINK_BEHAVIOR': true,
})
)
return config
}, |
@pauloamgomes do you have any more information on what exactly the flag does? i tried to track that down but it was pretty hard to follow. Are you setting that flag in the NextJS app as well? |
@pm0u it's super tricky indeed to track it down. You can see explanation here: vercel/next.js#36436, and it's equivalent of next.config.js -> There's an open PR at #19834 which will take care of this (for Next.js 12 projects that use the flag, or Next.js 13 projects by default). Will soon be available in the next versions of Storybook 7! |
@yannbf thanks. So, from what I gather this is not yet the default in Next13? That seems odd, since in use it does seem to be using the new link syntax in my NextJS app (13.0.3), which is the same version of Next used in my storybook (confirmed in the yarn.lock) without this ENV var set? |
Yes, the new link behavior is the default in Next13. But they engineered it in a way such that the behavior is dependent on that env var, which they set automatically within a Next app and must be manually applied when used outside of Next (which our PR does). |
Thank you for the explanation & fix! 🥇 that helps me a lot to increase confidence in working in storybook. cheers! |
Hurrah!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-alpha.52 containing PR #19834 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Describe the bug
[Reporduction repo available]
https://github.com/muhammad-saleh/storybook-next13-link
We were migrating one of our projects from Next.js 12 to 13, one of the new changes is a new
next/link
component. We use Chromatic to detect visual regressions. Migration was smooth until we found regressions with links.After investigation we found that Storybook doesn't emit props passed to the new
next/link
component, resulting in the anchors being rendered without styles.Example of a button rendered by the app:

HTML:

Same component rendered in Storybook:

HTML:

To Reproduce
System
Additional context
No response
The text was updated successfully, but these errors were encountered: