Next.js Discord

Discord Forum

Cache with Link

Unanswered
Saint Hubert Jura Hound posted this in #help-forum
Open in Discord
Saint Hubert Jura HoundOP
Hello, I have a nextjs page where in my layout I fetch data, and also in the page (different data). Then I have another page, where I have the same layout, and I fetch in this page other data. These 2 pages are accessible to each other via the Link components of nextjs. But the problem is that it doesn't refetch the page in I browse, it keeps everything cached. I even changed the fetchCache, the revalidate, it doesn't change anything. For information, I recover the data with the prisma client.
How can I force no cache?

25 Replies

@joulev it's due to the router cache and this issue might interest you: https://github.com/vercel/next.js/issues/42991
Saint Hubert Jura HoundOP
I'll take a look at that later thanks!
@joulev it's due to the router cache and this issue might interest you: https://github.com/vercel/next.js/issues/42991
Saint Hubert Jura HoundOP
I don't think that describes my problem.
Hmm, idk then, more information, e.g. a reproduction, is needed for me to know what’s wrong
Saint Hubert Jura HoundOP
this a video of the problem
this is the code of user page, and the problem is between this page and /user/[username]/likes page
@Saint Hubert Jura Hound this a video of the problem
Saint Hubert Jura HoundOP
when i dislike in the user page, the dislike not appear on the likes page and when i back to the user page
European sprat
Does the "your like was not saved" error message have something to do with it?
@European sprat Does the "your like was not saved" error message have something to do with it?
Saint Hubert Jura HoundOP
it displays this because the ui displays that I still like the thread while in database no. so it's trying to delete stuff that's already deleted.
European sprat
This just looks like what joulev said, router cache
You'll need some way to use revalidatePath, router.refresh(), use <a> tags or make them client components which use react-query or useSWR
All those have their own exceptions and issues but something like client component with react query will keep things showing the updated data when you expect it to be
Saint Hubert Jura HoundOP
the problem with revalidatePath or router refresh, is that the layout also reloads
European sprat
Client component with react query is your best bet then
Saint Hubert Jura HoundOP
but i use prisma client
European sprat
You put the Prisma logic in a function that the server component uses for initial render and also into a route handler that your client can fetch from
Transvaal lion
Sorry for the hijack. As been following this thread and the other one, been also having this caching issues.
But what's the use of Route Segment Config or the force no cache or next: { revalidate: 0 } if it all ends up relying on Route cache 30 seconds thing.
Nevermind, guess this answers it.
@Transvaal lion Sorry for the hijack. As been following this thread and the other one, been also having this caching issues. But what's the use of `Route Segment Config` or the force no cache or `next: { revalidate: 0 }` if it all ends up relying on Route cache 30 seconds thing.
European sprat
Force no cache and/or revalidate 0 are server settings.

Example:

User A loads the page, data is fetched
User B loads the page, data is fetched if not set to no-cache/revalidate 0
Saint Hubert Jura HoundOP
if i use fetch function i can fix my problem ?
@European sprat .
Saint Hubert Jura HoundOP
yes but it’s a hard solution
Saint Hubert Jura HoundOP
so there is no solution?