Hey , I tried to make a website on Next, the way you did on YT. All my features are working 'almost' fine on localhost. But when I have deployed it on vercel, the Home Page doesnt fetch the new data. That is, any CRUD operation is not reflected on the page. But if I redeploy it, then I can see all the expected prompts and their changes. I have tried many ways to resolve this issue, even trying to not let cache my fetch calls. But it doesn't work. Any help would b v appreciated!!! I have already spent a week to resolve this issue with no success. PFA git-hub link: https://github.com/hbansal90/PromptAISave.git , you will website link there itself
#Issues while Deployment of "Promptopia" On vercel
4 messages · Page 1 of 1 (latest)
I encountered a similar issue when deploying my app on Vercel. However, I was able to resolve it by updating the fetchPosts function to include the following changes:
const response = await fetch("/api/prompt", { next: { revalidate: 1 } });
Additionally, I made updates to the app/api/prompt/route.js file
import Prompt from "@models/prompt";
import { connectToDatabase } from "@utils/database";
import { NextRequest, NextResponse } from "next/server";
import { revalidatePath } from "next/cache";
export const GET = async (request) => {
try {
await connectToDatabase();
const prompts = await Prompt.find({}).populate("creator");
//To dynamically get the path
const path = request.nextUrl.searchParams.get("path") || "/";
revalidatePath(path);
return NextResponse.json(prompts);
} catch (error) {
return new Response("Failed to fetch all prompts", { status: 500 });
}
};
For a detailed explanation, you can refer to this YouTube video: https://www.youtube.com/watch?v=TZXMT-EG7Ak&t=98s
I hope that this helps you in resolving the issue.
Learn how to update data on a screen with the revalidatePath function in API Route Handlers.
NextChat: https://nextchat.ai
Other Videos:
Next.js 13 Server Actions: https://youtu.be/hD11c2mrq6Q
Master ChatGPT Prompt Engineering: https://youtu.be/oJWh5o0H2X4
NextChat.ai just killed ChatGPT: https://youtu.be/FyYgtlefjz0
#nextjs13 #revalidation
you can also refer to this https://stackoverflow.com/questions/76356803/data-not-updating-when-deployed-nextjs13-app-on-vercel-despite-using-cache-no/76751167#76751167
Thanks a lot , you are a life saviour XD. Now my website is working all fine. You can also visit my site,