Next.js server action view updates for only 1 user

45 views Asked by At

I'm using Next.js server actions to update customer account data. While customer data is of course unique to that customer, customer account paths aren't unique per customer. So all customers will be able to, for example, delete one of their addresses at the same path, /account/addresses.

Customer information is subject to change from a merchant database as well, so customer related fetch requests are not being cached. Additionally, router cache is being opted out of (prefetch={false}), and these pages are all dynamic.

In order to achieve a view update, I am currently revalidating the path after the server action of deleting an address is complete. Without doing this, for example, when a customer deletes an address, the removed address will persist in the view.

So finally on to the question, won't revalidating the path (again, this is a common path for all users) cause page updates for all users, when only the user who updated their data actually need the update?

For example if 2 users are on the view account/addresses page, and one customer removes their address, won't this cause an unnecessary partial re-render and refetch for the other customer as well? Beyond 2 customers to thousands of customers, this doesn't feel like it could possibly scale, unless I'm not thinking about this correctly.

I think if I could cache the customer addresses fetch (say tag it with the user's auth cookie or customer id) this could be revalidated in the server action, but a) I'm not clear that this would update the view with new html; b) because data is subject to change in a different application, caching anything customer related becomes very difficult/moot.

0

There are 0 answers