Next.js Discord

Discord Forum

Understanding caching

Unanswered
Montenegrin Mountain Hound posted this in #help-forum
Open in Discord
Montenegrin Mountain HoundOP
I thought I understood next/vercel caching but I'm hitting an issue and am finding it hard to figure out what's happening.

TLDR: I have a pageB.tsx which contains export const dynamic = "force-dynamic";.

It is linked to from pageA.tsx using a next <Link> (actually a link from next-view-transtions but I don't think this is significant).

The page calls a server function, let's call it const data = getData(), and the result is rendered on the page.

When I hit the page directly, everything works as expected and the latest data is rendered. However if I hit pageA first, then click the link to pageB, I get stale data, I think from build time.

If I open the network tab, I don't seem to be able to find the data coming down, but I can see a lot of GET requests that all have a x-vercel-cache: HIT header. This could just be static files required for the page?

Would appreciate any help finding the source of this stale cache...

8 Replies

Montenegrin Mountain HoundOP
ok can trace the source of the bad data to a request that ends with [page]?_rsc=1jhr
Montenegrin Mountain HoundOP
I think I'm seeing [this](https://github.com/vercel/next.js/issues/52727) issue. I tried setting prefetch={false} on my Link to no avail.
but note that this isn't a client side cache issue, I get the stale data if I navigate to page A and clear all browser storage, then click a Link to pageB.
Workaround is to replace <Link> with <a> but it's janky, I hate the full page reload experience.
Montenegrin Mountain HoundOP
Solution was revalidate = 0.
Docs confused me.
Chinese Alligator
I'm having an issue with Link where pages are cached, and when I edit a post and then go to the list, which is handled by a route with a revalidatePatch, it seems the cache isn't revalidated immediately unless I use server actions. I still haven't found the correct solution.