#caching

1 messages · Page 1 of 1 (latest)

thorn void
#

if i add js export const dynamic = 'force-dynamic' export const revalidate = 0
to my route handeler, does that mean it cannot be called from a client component?

boreal lintelBOT
#

Hi @thorn void. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Adding export const dynamic = 'force-dynamic' and export const revalidate = 0 to your route handler does not mean it cannot be called from a client component. These settings control the server-side behavior of your route.

The dynamic option, when set to 'force-dynamic', instructs Next.js to always render the route dynamically on the server, regardless of whether dynamic functions or uncached data requests are discovered during rendering (source (https://nextjs.org/docs/app/building-your-application/rendering/server-components#switching-to-dynamic-rendering)).

The revalidate option, when set to 0, disables Incremental Static Regeneration (ISR) for the route. This means that after the initial server-side rendering, the page will not be regenerated at intervals. Instead, the server-rendered page will be served until a new build occurs or the cache is invalidated (source (https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate)).

However, these settings do not prevent the route from being called from a client component. The client-side behavior of your application, including navigation between pages, is not directly affected by these settings. But it's important to note that the client-side router cache in Next.js can affect how often data is fetched from the server, and currently, there is no built-in way to opt out of this cache (source (https://github.com/vercel/next.js/issues/42991)).

#

If you want to ensure that the latest data is fetched from the server when navigating to a route, you may need to use a hard navigation (i.e., a full page reload) instead of a soft navigation (i.e., a client-side navigation using the Next.js <Link> component or the next/router API).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: