next.js
next.js copied to clipboard
router.refresh() causes intercepted route to switch to the intercepting route/modal
Link to the code that reproduces this issue
https://github.com/vercel/nextgram
To Reproduce
- Add code to
router.refresh()
on the intercepted route:
diff --git a/app/photos/[id]/page.tsx b/app/photos/[id]/page.tsx
index 4085ee7..45b6027 100644
--- a/app/photos/[id]/page.tsx
+++ b/app/photos/[id]/page.tsx
@@ -1,7 +1,18 @@
+'use client';
+
+import { useRouter } from 'next/navigation';
+
export default function PhotoPage({
params: { id },
}: {
params: { id: string };
}) {
- return <div className="card">{id}</div>;
+ const router = useRouter();
+
+ return (
+ <div className="card">
+ {id}
+ <button onClick={router.refresh}>Refresh</button>
+ </div>
+ );
}
- Click the refresh button.
Current vs. Expected behavior
I expect the route to stay the same on router.refresh()
.
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103
Binaries:
Node: 21.6.0
npm: 10.2.4
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.0.5-canary.67
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.3.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Routing (next/router, next/navigation, next/link)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed)
Additional context
https://github.com/vercel/next.js/assets/2367158/ee3300c2-662d-4aa8-8c42-0baa9264e516
This remains true of Next 14.1.
Additionally, this issue also occurs after a Fast Refresh caused by a file save while on the intercepted route.
Adding it to the bag of appRouter hard vs soft navigation on parallel routes? (ie: https://github.com/vercel/next.js/issues/60815 and https://github.com/vercel/next.js/issues/60814)
I'm just so frustrated with intercepted routes... I think i've ran into another bug, but i'm not sure if it's a bug or it's me being dumb, and i don't even know if it makes sense to report it.
If anyone has implemented authentication modals with intercepting routes and server actions, please share!
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.