force-dynamic Not Bypassing Cache for SSR Data When Only Query Params Change #76830
Unanswered
mertohancan
asked this question in
App Router
Replies: 1 comment
-
Hi @mertohancan , this is due to client/browser side Router Cache in Next.js 14. This cache is not able to opt out in 14. To clear the cache, both Setting |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
SSR Not Updating with
router.push()
Despiteforce-dynamic
in Next.js App RouterSummary
I am using Next.js App Router with
export const dynamic = 'force-dynamic';
to ensure that my page always fetches fresh SSR data when query parameters change. However, when I update query parameters usingrouter.push()
, Next.js still returns cached SSR data instead of fetching new data from the server.Expected Behavior
force-dynamic
is enabled, any change to query parameters should force a new SSR request and bypass any caching.Actual Behavior
router.push()
, and SSR props remain stale (cached).F5
) updates the data, proving thatforce-dynamic
works correctly on full reload but not on query param changes.router.refresh()
afterrouter.push()
fixes the issue but results in an extra server request, which should not be needed.Current Behavior
When the page first loads, filters are set based on server-rendered SSR data.
When a checkbox is clicked (applyFilter function runs), router.push() updates the URL correctly.
Query parameters are updated, but the SSR data (data.filters) remains cached and does not update.
If the page is manually refreshed (F5), the SSR data updates correctly.
If router.refresh() is called after router.push(), the SSR data updates, but this causes an extra server request.
Workarounds Tried
Question
Is this expected behavior, or is it a bug?
Shouldn't force-dynamic automatically bypass cache when query parameters change?
Why does Next.js return cached SSR data despite query changes, even with force-dynamic enabled?
Environment
Next.js Version: 14.x.x
App Router: ✅ Yes
Dynamic Route Handling: ✅ force-dynamic enabled
Beta Was this translation helpful? Give feedback.
All reactions