Revalidating Server Component from Route Handler
Unanswered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
I'm using next version 14.0.4 where i'm rendering my layout along with some data which i directly query from the db using Prisma.
I also have a weebhook exposed which is is working as expected, the issue is I'm unable to revalidate the layout from the weebhook route itself.
I have tried out revalidate path ( revalidate(
The data inside my database is correctly updating from the weebhook route which i have verified, i need to make sure that the layout gets rendered with the new data.
I also have a weebhook exposed which is is working as expected, the issue is I'm unable to revalidate the layout from the weebhook route itself.
I have tried out revalidate path ( revalidate(
/somePath) ) inside my route and route segment config inside my layout such as revalidate=0 but it does not work. The revalidate path for me is not dynamic i know which path to revalidate.The data inside my database is correctly updating from the weebhook route which i have verified, i need to make sure that the layout gets rendered with the new data.
9 Replies
Plott Hound
is this a typo?
( revalidate(/somePath) ) because it should be revalidatePath('/some/path');@Plott Hound is this a typo? `( revalidate(/somePath) )` because it should be `revalidatePath('/some/path');`
Northeast Congo LionOP
not a typo i just didn't add the literals
interestingly i found a similar issue which is still open, for anyone who is facing similar issue - https://github.com/vercel/next.js/issues/51788
Plott Hound
share the code for your route handler webhook
Northeast Congo LionOP
i cannot share the exact code but it goes something like this
export async function POST(req: NextRequest) {
const path = req.nextUrl.searchParams.get('path');
const body = await req.text();
const headerPayload = headers();
const auth = headerPayload.get('Authorization');
if (!auth) {
return new Response('No authorization header', { status: 400 });
}
const event = receiver.receive(body, auth);
// update the db
revalidatePath(`/${event.data.username}`);
return new Response('Successfully', { status: 200 });
}Northeast Congo LionOP
i tried unstable_store in my layout too but the data in the layout does not get revalidated 😦
const HomeLayout = async ({ children }: { children: React.ReactNode }) => {
noStore();
const users = await getUsers();
// console.log("did i got revalidated");
return (
<>
<Navbar />
<main className="flex h-full pt-20">
<Suspense fallback={<SideBarSkeleton />}>
<SideBar data={users} />
</Suspense>
<Container>{children}</Container>
</main>
</>
);
};Plott Hound
Is the path for the revalidation correct?
Could you try it with this instead just to make sure it’s not an incorrect path
revalidatePath('/', 'layout')