Next.js Discord

Discord Forum

Revalidate Path not working as expected

Unanswered
Tan posted this in #help-forum
Open in Discord
Avatar
TanOP
I am working on a addToCart functionality of a pizza ordering application, in the handle-click function (which is on a client component) i call the server function with required params, and in the server function I implement logic to add item to cart and revalidatePath('cart') and redirect('cart'), but the cart page behaves differently. It shows the pizza in cart when I add it for first time but then it doesn't on subsequent addToCart calls, i have to manually reload to see the item in cart. What could I be doing wrong ? (I am new to nextJs!)
Image
Image

4 Replies

Avatar
SupremeDeity
Didnt read the code but firstly, revalidate functions work on subsequent requests and secondly you shouldn't need to revalidate when you are using "react state" and its all on the same page
Avatar
TanOP
It's not on the same page I have a pizza page which includes a pizzaOptions component (client component) which is responsible for making a call to handleClick function which in turn calls the addToCart server function which should create order and orderItems in my DB and redirect to the cart page where they will be rendered
Avatar
TanOP