Next.js: Add useLinkStatus mock to next/link export mock#34593
Conversation
Adds the `useLinkStatus` hook (introduced in Next.js 15.3) to the `@storybook/nextjs/link.mock` module. Without this export, Storybook fails at build and runtime when a component imports `useLinkStatus` from `next/link`. Also exports the `LinkStatus` type to match the Next.js public API. https://claude.ai/code/session_01Hw1UdSNqtAb34tbqFFw14S
Formatter normalised single quotes to double quotes in code blocks. https://claude.ai/code/session_01Hw1UdSNqtAb34tbqFFw14S
Adds two template stories to Link.stories.tsx:
- DefaultLinkStatus: asserts the mock returns { pending: false } by default
- PendingLinkStatus: demonstrates overriding via beforeEach + mockReturnValue
Follows the same pattern used in Navigation.stories.tsx and ServerActions.stories.tsx.
https://claude.ai/code/session_01Hw1UdSNqtAb34tbqFFw14S
Undoes auto-formatter quote changes that were inadvertently committed. https://claude.ai/code/session_01Hw1UdSNqtAb34tbqFFw14S
No other mock manually exports types — they rely on re-exporting from the real Next.js dist modules. Keeping this consistent; the inline return type on useLinkStatus is sufficient for type inference. https://claude.ai/code/session_01Hw1UdSNqtAb34tbqFFw14S
42814c0 to
3ada6df
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis adds a new Storybook mock for the Next.js Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
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. Comment |
|
Thank you so much for contributing the fix. Would you mind implementing a fix for https://github.com/storybookjs/vite-plugin-storybook-nextjs |
Hey @valentinpalkovic :) I wasn't sure what to do about I noticed there's no Would I be able to copy the same code across from the non-Vite version? |
|
You're right. We don't have a LinkMock equivalent in nextjs-vite. That's a shame. @yatishgoel since you have contributed the initial implementation of |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 72 | 60 | 🎉 -12 🎉 |
| Self size | 20.30 MB | 20.52 MB | 🚨 +217 KB 🚨 |
| Dependency size | 36.17 MB | 32.84 MB | 🎉 -3.34 MB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/nextjs-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 93 | 93 | 0 |
| Self size | 1.38 MB | 1.37 MB | 🎉 -13 KB 🎉 |
| Dependency size | 24.78 MB | 24.78 MB | 🎉 -400 B 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 203 | 194 | 🎉 -9 🎉 |
| Self size | 908 KB | 908 KB | 🎉 -144 B 🎉 |
| Dependency size | 87.59 MB | 84.57 MB | 🎉 -3.02 MB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 196 | 187 | 🎉 -9 🎉 |
| Self size | 32 KB | 32 KB | 0 B |
| Dependency size | 86.08 MB | 83.06 MB | 🎉 -3.02 MB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 73 | 61 | 🎉 -12 🎉 |
| Self size | 1.08 MB | 1.08 MB | 0 B |
| Dependency size | 56.48 MB | 53.36 MB | 🎉 -3.12 MB 🎉 |
| Bundle Size Analyzer | node | node |
…-uselink-status-hook-ctuWL Next.js: Add useLinkStatus mock to next/link export mock (cherry picked from commit a754286)
Next 15.3 introduced the
useLinkStatushook:When
useLinkStatusis used in a component that is presented in a story then Storybook users get errors like this one:or this in the Storybook server output:
What I did
Added an export for
useLinkStatus, which defaults to{ pending: false }but can be overridden via mock. The code was written by Claude Code so let me know if there's anything that isn't in keeping with how Storybook normally does things and I'll make the changes.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
I tried testing via
yarn task sandbox --template nextjs/default-ts --start-from autoand following the instructions inCONTRIBUTING.mdbut got lost and couldn't get a local version of the nextjs package running locally to test with.We can use the CI build to test the work via the new
DefaultLinkStatusandPendingLinkStatusstories.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake 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/coreteam 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
useLinkStatushook mock for Storybook to track Next.js Link navigation states.Tests