[v13 + appDir] prefetch={false} breaks client-side navigation
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Wed Aug 24 22:24:20 UTC 2022
Binaries:
Node: 19.0.0
npm: 8.19.2
Yarn: 1.22.19
pnpm: 7.14.1
Relevant packages:
next: 13.0.1-canary.1
eslint-config-next: 13.0.1-canary.1
react: 0.0.0-experimental-cf3932be5-20221027
react-dom: 0.0.0-experimental-cf3932be5-20221027
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
Adding prefetch={false} to a link breaks client-side navigation. Clicking on the link causes a full page navigation (no error is thrown).
IMPORTANT: If there is another for the same path with prefetch enabled, then the Link with prefetch=false also works correctly. You can uncomment the 2nd link in the StackBlitz to reproduce that behavior as well.
Expected Behavior
Clicking on a link with prefetch={false} should perform a client-side navigation.
Link to reproduction
https://stackblitz.com/edit/vercel-next-js-no-client-side-nav?file=app%2Fpage.tsx
To Reproduce
Open homepage and click on the link. You can confirm the full page navigation via the browser's console.
I can confirm. I am seeing similar issues when trying to prefetch dynamic routes like app/test/[testId]/leaf/page.tsx where the prefetching systematically fails on Vercel (but works fine with next dev & start) and leads to a complete page reload.
I am also seeing the same issue when setting headers to the request in the middleware (as allowed in Next 13 https://nextjs.org/docs/advanced-features/middleware), prefetching systematically fails/halt.
So the behavior you described is due to forcing OptimisticNavigation when calling the router in link.tsx when prefetching is disabled. Not sure it was the intended behavior, but seems like it.
https://github.com/vercel/next.js/blob/0affdebf67b0b94d409285906e250acb19b2cca1/packages/next/client/link.tsx#L186-L188
https://github.com/vercel/next.js/blob/4316d3884e1ab7c4cec94c21e4b4928d33eeb079/packages/next/client/components/reducer.ts#L835-L839
The issue on Vercel does not seem to be related to this.
Same issue with prefetch={false}
Any news on this?
I think that @timneutkens told before in another issue that is currently the excepted behavior. Can you confirm?
Let's say we have a page with 50 visible links (let's name it contest) to other pages (contest_result/[id]). Contest results is a page that has let's say 500kb of