<Link> prefetching behavior #60581
Replies: 4 comments 2 replies
-
What happens when the user clicks on the link? Maybe you should switch it to a regular |
Beta Was this translation helpful? Give feedback.
-
How does Next actually handle prefetching for "dynamic" routes like this? Does it just invoke the entire route, including calls to |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Context
Why Fix (minimum viable)
Notes
If this helps, please Mark as answer so others can find it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
No response
Background
I'm working on a project using Next 14 and app router. We have a route for logging users out. This route just deletes some cookies then redirects the user to another page.
The route exists in the app directory and the folder

logout
only hasroute.ts
as shown downNow the only missing piece is having a component that goes to /logout as shown down

The problem is that Next will prefetch /logout if we don't pass prefetch={false}. This is really unsafe and in our case it leads to the user being signed out the moment he logs in to their account.
Proposal
I haven't really thought of anything to solve this DX experience but an ideal solution would be that Next only prefetches routes that actually serve some content
since pages in app router are not allowed to set or delete cookies, it's safe to prefetch only routes that actually serve some content
Beta Was this translation helpful? Give feedback.
All reactions