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
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

American Cocker SpanielOP
@Anay-208 | Ping in replies thank you in advance
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
Pass from server component
American Cocker SpanielOP
still not working
I don't see why
@Anay-208 | Ping in replies Pass from server component
American Cocker SpanielOP
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