useRouter().refresh() does not revalidate client cache when used with push() #77552
Unanswered
developer-choi
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using
useRouter().refresh()
together withpush()
, the client router cache does not get properly revalidated.I have prepared an example based on a real scenario where this bug occurs.
And of course, a minimal reproducible example is also available.
Background
router.refresh()
and thenrouter.push('/admin-notice/list')
to go back to the list page.{ cache: 'no-store' }
,It seems that despite calling router.refresh(), the list page is still retained in the Client Router Cache.
Reproduction Steps
Expected behavior of router.refresh()
You can reproduce the exact same issue by following this video: Youtube Video.
Just go to http://localhost:3000/expected/three.
If you create your layout like this and navigate between pages under that layout, you’ll notice that calling
router.refresh()
does clear the Client Router Cache.In the video, you can see that when you revisit a previously visited page, it loads instantly (because it's cached).
But after calling
router.refresh()
, visiting that same page again takes time, just like the first visit — indicating that the cache was cleared.Unexpected behavior of router.refresh()
However, if you change the layout like this and test it again, you’ll see that even though
router.refresh()
is called, the Client Router Cache is not cleared.You can observe this behavior at http://localhost:3000/unexpected/three.
I suspect that when
router.refresh()
is used together withrouter.push()
, the Client Router Cache does not get invalidated.Beta Was this translation helpful? Give feedback.
All reactions