Next.js Discord

Discord Forum

Server Component data not getting re-fetched when using browser's back and forward buttons.

Unanswered
Atlantic herring posted this in #help-forum
Open in Discord
Avatar
Atlantic herringOP
I have a server action that fetches products on the "/products" route, which is a server component. After waiting for 30 seconds for the Router Cache to clear, the route fetches and returns the latest products when using the Next.js Link Component directed to the "/products" route. However, the same does not occur when I use the browser's back and forward buttons, instead, the old data is returned without any server request. Can anyone help me understand this behaviour, or is it a bug?

3 Replies

Avatar
Atlantic herringOP
Hello? Could someone's help me here.
Avatar
Wool sower gall maker
try cache: 'no-store' option in your fetch request
Avatar
Atlantic herringOP
Thanks for the reply, but I am already using revalidate=0 and dynamic="force-dynamic" in the page.tsx of "/products" route and I am using axios, so the cache: 'no-store' of the extended fetch API will not work here, I think this issue is related to client side Router Cache, as the latest data is fetched if I visit the "/products" route through Link Component, but the same will not work If I am on home page and use browser's forward button to visit the "/products" route, and also when using the Link Component there is a server request in network tab of developer tools and there is no server request when visiting the route using browser's forward button.