Next.js Discord

Discord Forum

On-demand revalidation

Answered
Western thatching ant posted this in #help-forum
Open in Discord
Avatar
Western thatching antOP
Imagine having 1 counter that starts at 0, and a button that says increment. Now imagine 2 clients on that same page. One of the clients presses increments, and in the server action, we call revalidatePath("/"). This will update the request, and show the counter at 1. For the other client, the counter is still 0.

Is there a way (other than webhooks/websockets, which is a way right?) to revalidate on demand but not for the next request, but the current one? Client #2 can referesh the page a have the counter at 1, but how can it have the counter at 1 automatically?
Answered by joulev
Nextjs doesnt have real-time capabilities. See also: https://nextjs-forum.com/post/1216996751718879343#message-1217000530715480084
View full answer

5 Replies

Avatar
American Crow
It's a bit hard to understand but should be possible with revalidateTag?
https://nextjs.org/docs/app/api-reference/functions/revalidateTag
Ah no, reading it again now i think i understand it. You basically have 2 browsers open simulating 2 clients. Doing a revlidatePath from client 1 and want the result to be shown to client 2 as well (without refreshing)
Don't think thats possible if client 2 is just idle doing nothing the whole time, no new request is happening.
(other than client side polling, using something like react query)
Avatar
joulev
Nextjs doesnt have real-time capabilities. See also: https://nextjs-forum.com/post/1216996751718879343#message-1217000530715480084
Answer