Issue with Vercel data cache in production, new posts are not fetched
Unanswered
American Cocker Spaniel posted this in #help-forum
American Cocker SpanielOP
In my project I fetch new posts like this :
it works fine on local, but not on production. I have to clear the Vercel data cache manually to be able to see new posts.
useEffect(() => {
const fetchPosts = async () => {
try {
const response = await fetch(POSTS_RECOMMANDES_API_SUGGESTION, {
next: { revalidate: 50 },
});
const data = await response.json()
setPosts(data)
} catch (error) {
console.error(POSTS_RECOMMANDES_ERROR_FETCH_POSTS_MESSAGE, error)
} finally {
setLoading(false)
}
}
fetchPosts()
}, [])
it works fine on local, but not on production. I have to clear the Vercel data cache manually to be able to see new posts.
14 Replies
American Cocker SpanielOP
@Anay-208 thank you in advance
It doesn’t work on client side.
You’ve to do stuff with cache on server side
You’ve to do stuff with cache on server side
And I recommend using server components for fetching data(if it doesn’t require any client interaction)
American Cocker SpanielOP
but in the doc they do like this : https://vercel.com/docs/infrastructure/data-cache
this is client side
ok I get it, it's a server component
thanks I will try fetching the data from the layout then pass into this page
No not layout
Pass from server component
American Cocker SpanielOP
still not working
I don't see why
could you help me have a look 🥲 not sure why Vercel is so hard on this cache thing
American Cocker SpanielOP
ok it's working, I need to add export const dynamic = "force-dynamic"; in route.ts file. But it's not mentioned in the doc
As mentioned, you don’t need to do it in layout