Next.js Discord

Discord Forum

Calling a function from Route with random results ends up with same result on Vercel but not local

Unanswered
Podenco Canario posted this in #help-forum
Open in Discord
Podenco CanarioOP
Hi,

I'm trying to required a function from my server side of a NextJS app like so :

  // Get game at random
  const {
    data: game,
    error: gameError
  } = await supabase.rpc('choose_random_game')


In local the variable "game" does send a new random game each time, but when I deploy on Vercel the value stays the same every time I require my route.

Does Vercel tries to use some sort of cache instead of getting a new value for game ?
I think this is what is called "Edge Functions" in Next but I'm not very sure about that nor how it is called on Vercel to know what to look for in the documention.

9 Replies

do npm run build
npm run start

your gonna see it match vercel results
prod cache is diff from dev cache
Podenco CanarioOP
I've tested a few things out, and it seems like I have to add export const dynamic = 'force-dynamic' on some routes.
I'm not sure if I should do this on all my API Routes but it seems to work as intended
you shld react the nextjs docs on caching
nextjs has a opt out system for caching, not opt in
Podenco CanarioOP
I'm sorry I don't get the "opt out" and "opt in" thing ?
so you need to opt out of it, instead of how most languages/frameworks make you do the caching
Podenco CanarioOP
Ok I see, so for all my dynamic routes I have to specify "I want this result to be dynamic", or else it will just take whatever the first result were instead of doing a new request to my third party lib 👍
Thanks for the hints 😁 I think I get it now