Does revalidatePath (say after a server action) revalidate for all logged in user's dashboard ?
Answered
Yellow croaker posted this in #help-forum
Yellow croakerOP
is it better to use a library like react-query to maintain fresh data than to just rely on next.js 's re-invalidate ?
Answered by B33fb0n3
Yes, it’s for all users, that uses the specific route. If you want to revalidate only specific parts of your app, you can use „revalidateTag“.
revalidatePath and revalidateTag are both for serverside data fetching.
React query is for clientside data fetching. So if you need somewhere clientside data fetching, you can revalidate these queries clientside as well
revalidatePath and revalidateTag are both for serverside data fetching.
React query is for clientside data fetching. So if you need somewhere clientside data fetching, you can revalidate these queries clientside as well
5 Replies
@Yellow croaker is it better to use a library like react-query to maintain fresh data than to just rely on next.js 's re-invalidate ?
Yes, it’s for all users, that uses the specific route. If you want to revalidate only specific parts of your app, you can use „revalidateTag“.
revalidatePath and revalidateTag are both for serverside data fetching.
React query is for clientside data fetching. So if you need somewhere clientside data fetching, you can revalidate these queries clientside as well
revalidatePath and revalidateTag are both for serverside data fetching.
React query is for clientside data fetching. So if you need somewhere clientside data fetching, you can revalidate these queries clientside as well
Answer
@B33fb0n3 Yes, it’s for all users, that uses the specific route. If you want to revalidate only specific parts of your app, you can use „revalidateTag“.
revalidatePath and revalidateTag are both for serverside data fetching.
React query is for clientside data fetching. So if you need somewhere clientside data fetching, you can revalidate these queries clientside as well
Yellow croakerOP
thank you,
Just to clarify, in this scenerio.
My app is an isolated todo list for each registered user. Simple app, user that submits a new todo, it gets updated in their list.
1. I have a server component that queries that user's todo existing entries base on client authorization header. (accessing header will disable cache)
2. if any of the user makes a form submission (adds a new item to list) . having revalidatePath in server action doesn't purge any cache on server side because it was never cached. Correct me if im wrong, but it still clears the "client-side Router Cache" of the user that initialized the server action right ? Effectively, this triggers server to get the latest data and update my client (behaviour that I want).
Just to clarify, in this scenerio.
My app is an isolated todo list for each registered user. Simple app, user that submits a new todo, it gets updated in their list.
1. I have a server component that queries that user's todo existing entries base on client authorization header. (accessing header will disable cache)
2. if any of the user makes a form submission (adds a new item to list) . having revalidatePath in server action doesn't purge any cache on server side because it was never cached. Correct me if im wrong, but it still clears the "client-side Router Cache" of the user that initialized the server action right ? Effectively, this triggers server to get the latest data and update my client (behaviour that I want).
Yellow croakerOP
alright, i think i can just use
router.refresh()@Yellow croaker thank you,
Just to clarify, in this scenerio.
My app is an isolated todo list for each registered user. Simple app, user that submits a new todo, it gets updated in their list.
1. I have a server component that queries that user's todo existing entries base on client authorization header. (accessing header will disable cache)
2. if any of the user makes a form submission (adds a new item to list) . having revalidatePath in server action doesn't purge any cache on server side because it was never cached. Correct me if im wrong, but it still clears the "client-side Router Cache" of the user that initialized the server action right ? Effectively, this triggers server to get the latest data and update my client (behaviour that I want).
revalidatePath revalidates the whole path that you entered. So it will revalidate also the serverside data cache, refetch the data from your data source and updates the html parts on the clientside to show the new data.
So it’s like a full page reload, without the client sees the reload.
Of course that’s possible, but I wouldn’t do it like that. Especially when you have multiple SS fetches on your side that all will be revalidated and refetched even when they don’t need to be refetched.
It’s ok to do clientside fetching and keep in mind to use a clientside fetching library like swr or react query
So it’s like a full page reload, without the client sees the reload.
Of course that’s possible, but I wouldn’t do it like that. Especially when you have multiple SS fetches on your side that all will be revalidated and refetched even when they don’t need to be refetched.
It’s ok to do clientside fetching and keep in mind to use a clientside fetching library like swr or react query