-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Next.js: Fix Link component override in appDirectory configuration #31251
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
Merged
valentinpalkovic
merged 12 commits into
storybookjs:next
from
yatishgoel:fix/nextjs15-link-component-override
Feb 11, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b3e8ea8
feat: Update Storybook Header component and related configurations
yatishgoel 8c50b52
Merge branch 'next' into fix/nextjs15-link-component-override
yatishgoel 01e498a
Merge branch 'next' into fix/nextjs15-link-component-override
valentinpalkovic 1330387
Merge branch 'next' into fix/nextjs15-link-component-override
valentinpalkovic 5a45292
Merge branch 'next' into fix/nextjs15-link-component-override
yatishgoel ca1693a
Merge branch 'next' into fix/nextjs15-link-component-override
valentinpalkovic e9b5ab1
Update Next.js package.json to include code path for link mock
yatishgoel 372b103
Merge branch 'storybookjs:next' into fix/nextjs15-link-component-over…
yatishgoel 41d8856
Enhance Next.js build configuration by adding link mock entry and upd…
yatishgoel 7bc1553
Refactor Next.js link mock implementation to enhance functionality an…
yatishgoel 25e35bc
Merge branch 'next' into fix/nextjs15-link-component-override
yatishgoel 27628cd
Fix: Add missing import statement in Next.js link mock implementation…
yatishgoel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { fn } from 'storybook/test'; | ||
|
|
||
| const linkAction = fn().mockName('next/link::Link'); | ||
|
|
||
| const MockLink = React.forwardRef<HTMLAnchorElement, any>(function MockLink( | ||
| { | ||
| href, | ||
| as: _as, | ||
| replace, | ||
| scroll, | ||
| shallow, | ||
| prefetch, | ||
| passHref, | ||
| legacyBehavior, | ||
| locale, | ||
| onClick, | ||
| children, | ||
| ...rest | ||
| }, | ||
| ref | ||
| ) { | ||
| const hrefString = | ||
| typeof href === 'object' | ||
| ? `${href.pathname || ''}${href.query ? '?' + new URLSearchParams(href.query).toString() : ''}${href.hash || ''}` | ||
| : href; | ||
|
|
||
| const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||
| e.preventDefault(); | ||
| onClick?.(e); | ||
| linkAction(hrefString, { replace, scroll, shallow, prefetch, locale }); | ||
| }; | ||
|
|
||
| return ( | ||
| <a ref={ref} href={hrefString} onClick={handleClick} {...rest}> | ||
| {children} | ||
| </a> | ||
| ); | ||
| }); | ||
|
|
||
| MockLink.displayName = 'NextLink'; | ||
|
|
||
| export default MockLink; | ||
| export { MockLink as Link }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if
legacyBehavioris true, this should pass the props onto the child instead of rendering an<a>itself. #33861See here: https://github.com/vercel/next.js/blob/b0595b17ae331a2e1cccff35da8d093f0636c8e1/packages/next/src/client/link.tsx#L680-L690