#Stale data in App directory

1 messages · Page 1 of 1 (latest)

rustic sandBOT
#

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

#

Based on the information extracts provided, it seems that you are using the new app directory in Next.js, which uses server-centric routing with client-side navigation. This means that when a user navigates to a new route, the browser will not reload the page, and the URL will be updated without making a new server request (source (https://beta.nextjs.org/docs/routing/fundamentals#partial-rendering)).

However, the extracts do not provide enough information on how to force a server round-trip for a specific page in the app directory. I recommend checking the Next.js documentation (https://nextjs.org/docs) for more information on this topic.

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

Get started with Next.js in the official documentation, and learn more about all our features!

Next.js 13 introduced the new App Router built on top of React Server Components with support for layouts, nested routing, loading states, error handling, and more.

#

@willow lynx kapa.ai is still learning and improving, please let us how it did by reacting below

willow lynx
#

@rustic sand How should I work with server side data then if the server is not called when navigating?

rustic sandBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

When working with server-side data in Next.js, you can use getServerSideProps to fetch data on each request. However, since you're using the new app directory, the routing behavior is different, and the server is not called on every navigation.

To fetch data on the client-side when navigating, you can use the useEffect hook or a library like SWR (https://swr.vercel.app/). This approach allows you to fetch data when the component mounts or when specific dependencies change.

Here's an example of fetching data on the client-side using SWR:

import useSWR from 'swr'

function ProfileForm({ userEmail, type }) {
  const { data: profile, error } = useSWR(`/api/profile/${userEmail}`, fetcher)

  if (error) return <div>Failed to load</div>
  if (!profile) return <div>Loading...</div>

  // Render the profile data
}

export default ProfileForm

In this example, the ProfileForm component fetches the profile data on the client-side using SWR. When navigating to the edit page, the data will be fetched again, ensuring that you have the latest data (source (https://nextjs.org/docs/basic-features/layouts#data-fetching)).

Keep in mind that this approach fetches data on the client-side, so it may not be suitable for all use cases. If you need to fetch data on the server-side, you might need to look into the Next.js documentation for more information on how to handle server-side data fetching with the new app directory.

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

Learn how to share components and state between Next.js pages with Layouts.

#

@willow lynx kapa.ai is still learning and improving, please let us how it did by reacting below

willow lynx
#

@rustic sand I've set my Route Segment Config Options to revalidate = 0 and firce-dynamic so it should always re-render my server side components, but it keeps stale data in my frontend and does not do a server side round-trip. How can I fix this?

rustic sandBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Hmm, I don't know enough to give you a confident answer yet. The information extracts provided do not cover the specific case of using revalidate = 0 and force-dynamic with the new app directory in Next.js. I recommend checking the Next.js documentation (https://nextjs.org/docs) for more information on this topic.

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

Get started with Next.js in the official documentation, and learn more about all our features!