Can't get updated data after update data in production
hello, im using next js with prisma orm and SWR with axios for fetching from client and free tier neon database
in my next js app, after updating the data and revalidate the data using swr, the data that i get is old data, this only happen in production mode even the database data is updated.
but if in dev mode, its updated succesfully and always get new data
this is what i already tried:
- increasing or disable connection timeout and pool timeout
- using pooled connection and direct connection url
any suggestions?
7 Replies
itchy-amethyst•2y ago
Can you explain what dev mode and production mode are? Are you using branching within Neon?
Have you tried using psql or the Neon SQL Editor to make the same query
rare-sapphireOP•2y ago
Can you explain what dev mode and production mode are?
dev mode is running on localhost using next dev
production mode is using next build then running next start in localhost, or running on vercel
Are you using branching within Neon?
no
Have you tried using psql or the Neon SQL Editor to make the same query
i'm using prisma studio and neon sql editor, the data its updated while update the data
like-gold•2y ago
I've seen similar behaviour reported before.
In those instances, the local deployment was falling back to a local postgres instance -- so it was writing local, vs the cloud.
You can test this by performing a write in the application, then running a query on the console to see if the data is there.
You can try the reverse by writing using a query at the console, then pulling a local read.
Try simplifying your test harness:
rare-sapphireOP•2y ago
Oh, on my dev mode i setup the database url is connecting to the neon database, so im sure its not connect to the local db
So, at the dev mode or production mode, im using same neon db url
constant-blue•2y ago
@Daniel Tan you say this only happens in production, and you're sure the database is updated? In that case this would suggest it's an issue with SWR/Next,js right?
SWR does perform caching AFAIK, so perhaps that's what's happening? Check the Network inspector in DevTools to see SWR is actually fetching new data from the backend, and make sure that it's what you expect.
I'm not an expert in Next.js but you might also need
export const dynamic = 'force-dynamic' in your API route to make sure it always performs a query aginst the db?rare-sapphireOP•2y ago
ok, i will find out about it
update:
after i add its finally working
so its because next js caching
thanks for the help
constant-blue•2y ago
Youre welcome!