#Stale data in App directory
1 messages · Page 1 of 1 (latest)
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:
@willow lynx kapa.ai is still learning and improving, please let us how it did by reacting below
@rustic sand How should I work with server side data then if the server is not called when navigating?
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:
@willow lynx kapa.ai is still learning and improving, please let us how it did by reacting below
@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?
Let me check the knowledge base for you again. One moment! :books: