Next.js Discord

Discord Forum

Issue with Vercel data cache in production, new posts are not fetched

Unanswered
American Cocker Spaniel posted this in #help-forum
Open in Discord
Avatar
American Cocker SpanielOP
In my project I fetch new posts like this :

   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

Avatar
American Cocker SpanielOP
@Anay-208 thank you in advance
Avatar
It doesn’t work on client 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)
Avatar
American Cocker SpanielOP
but in the doc they do like this : https://vercel.com/docs/infrastructure/data-cache
this is client side
Image
ok I get it, it's a server component
thanks I will try fetching the data from the layout then pass into this page
Avatar
No not layout
Pass from server component
Avatar
American Cocker SpanielOP
still not working
I don't see why
Image
Image
could you help me have a look 🥲 not sure why Vercel is so hard on this cache thing
Avatar
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
Avatar
As mentioned, you don’t need to do it in layout