Next.js Discord

Discord Forum

How come calling router.refresh() only refreshes the page once?

Unanswered
English Angora posted this in #help-forum
Open in Discord
English AngoraOP
e.g.

  <Button
    onClick={() => {                  
      router.refresh();                  
    }}
  >
    Click
  </Button>


Clicking on this button refreshes the page once (i.e. you can see loading.tsx execute), but afterwards it doesn't refresh anything.

12 Replies

@English Angora e.g. <Button onClick={() => { router.refresh(); }} > Click </Button> Clicking on this button refreshes the page once (i.e. you can see loading.tsx execute), but afterwards it doesn't refresh anything.
the router also checks if there are state changes and only updates these state changes. It's different from doing window.location.reload(). With the window function there are no check against the state and the page would reload normally
English AngoraOP
I see... is there a way to force a reload using router.refresh then? I'm trying to show changes on a page after a user presses a button that writes some data to the a db, but the changes don't display even when i use revalidatePath (which was why i started looking into router.refresh in the first place)
English AngoraOP
Sorry what do you mean by push state? Do you mean use something like useState to manage state on the client instead of passing it through server components?
Thanks for answering all my questions btw I appreciate it
English AngoraOP
Yep (alongside unstable_cache) but it didn't work as expected... I thought revalidateTag was always supposed to refresh the current page but it didnt
yea, normally that would happen 🤔
Do you use any other caches?
@B33fb0n3 is there a reason why that does not work?
it does work but only after you reload the page
a browser reload