Updated data not being fetched in production.

Hey guys so i just made a web app which uses prisma / planetscale and tanstack query. I have been trying to fetch data from the code below
const { data, refetch, isRefetching } = useQuery({
queryKey: ["normal_fetch"],
queryFn: async () => {
const { data } = await axios.get("/api/votes/fetchVote");
return data as VoteProps[];
},
onError: (err) => {
if (err instanceof AxiosError) {
if (err.response?.status === 401) {
return console.log("errror");
}
}
},
});
const { data, refetch, isRefetching } = useQuery({
queryKey: ["normal_fetch"],
queryFn: async () => {
const { data } = await axios.get("/api/votes/fetchVote");
return data as VoteProps[];
},
onError: (err) => {
if (err instanceof AxiosError) {
if (err.response?.status === 401) {
return console.log("errror");
}
}
},
});
It works perfectly fine in the local enviroment but the deployed version of the app doesn't fetch the updated data from database at all what might be the problem here ?
S
swikarrr311d ago
import { db } from "@/lib/db";
import { z } from "zod";

export async function GET(req: Request) {
try {
const votes = await db.vote.findMany();
return new Response(JSON.stringify(votes));
} catch (error) {
if (error instanceof z.ZodError) {
return new Response("Invalid request data passed", { status: 422 });
}

return new Response("Could not fetch the data.", {
status: 500,
});
}
}
import { db } from "@/lib/db";
import { z } from "zod";

export async function GET(req: Request) {
try {
const votes = await db.vote.findMany();
return new Response(JSON.stringify(votes));
} catch (error) {
if (error instanceof z.ZodError) {
return new Response("Invalid request data passed", { status: 422 });
}

return new Response("Could not fetch the data.", {
status: 500,
});
}
}
this one is route
A
Apestein311d ago
https://nextjs.org/docs/app/building-your-application/routing/router-handlers#behavior Try with NextResponse, your route is probably being statically evaluated.
S
swikarrr311d ago
thank you , but i got it it was happening because of caching
A
Apestein311d ago
how did you fix it?
S
swikarrr311d ago
i just needed to revalidate the data fetching apparently it was calling the api for 1 time and then using that throughout so i added export const revalidate = 0; at top my route
A
Apestein310d ago
Yeah, it was statically evaluated, you just forced to it to be dynamic. Usually, you wouldn't need to do that since using the Request object should automatically make the route dynamic by default.
Want results from more Discord servers?
Add your server
More Posts
Some good old system designHello everyone, how you doing ? So I want to create a little app that consists of 2 main parts sysPages or App ?I'm going to create a production project with nextjs, but confused, What is the best option pages/ oWait for ISR Revalidation (rather than showing stale data)Hey guys! I had a quick question about using ISR in Next.js (app router) with Vercel. As outlined byWhat about Panda CSS?Hey there! I can't find any talk about using Panda CSS over Tailwind on this Discord. I would like tNextAuth sign in function not working properlyhey, i have nextauth set up with `credentialsProvider` on, i have the following onClick on a button:Fetching only onceso i have an authToken being stored in the local storage and i want to send it in a POST request eacimport mysql into planetscaleHas anyone imported a database from your local pc into planetscale? With regard to the hostname whatPromise.all is not working in transaction in drizzleCan anyone tell me why this transaction is not working in drizzle? it does not throwing any error bshortest import path with eslint + tsconfig.json pathsIs there any way to configure eslint (I am using `eslint-plugin-import` + `eslint-import-resolver-tyGitHub workflow doesnt runI have this PR here which requires the CI to pass but it doesnt run. Do I miss something or have I sgetServerAuthSession returning null in productionI have absolutely no clue how that is happening because I've implemented the same solution in anotheNot able to get the jwt token through cookiesHii all I'm trying to send the jwt token through cookies like first image .. Now I 'm trying to fetcNext api routes stoped working since clerk installedI installed clerk in my app and auth is working as expected. My probles is that all my api routes stDisable batching multiple useQueryI'm using useQuery as below: ``` const CompanyPage: NextPage<{ asxCode: string }> = ({ asxCode }) =>TypeScriptHi guys i am trying to learn TypeScript. Is there any good resources you can suggest besides the docZod type email string and number message not working correctlyHey guys i am facing a issue i am also new to typescript ```ts const authschem = z.object({ email