I’m building a SaaS platform that is private. That means only authenticated users are able to interact with it.
So I’m deciding between using a fully React Server Components approach (with Server Actions, etc), or a hybrid approach; that is regular NextJS with client components that fetch API endpoints once mounted.
Both have tradeoffs but my main considerations are:
First approach:
(Good)
- With first approach (RSC) I can directly get the data without an additional “round trip” to the API endpoints once mounted in the client.
- That means also not exposing public endpoints other than the authentication ones.
- I can use Suspense to achieve a decent UX even when waiting from the server.
(Bad) - For what I’ve exploring and testing, when I revalidate a path after a server action, it will call all data requests even in the layout, which is not optimal.
- How performant and infrastructure optimal is to call always the server.
On the other hand, with a more “client-oriented” option (fetching from the client with React Query for example):
(Good)
- Maybe more flexibility? Since I can invalidate queries and reuse cache data from the client if I need it.
- That may be important because I’ll build dashboards or highly interactive UIs.
(bad)
- A not so clear workaround on hydrating the server side state into React Query in the client, etc.
- Losing the advantages of RSC like being able to start fetching even before rendering, not having to maintain a separate public api endpoints, etc.
Can you guide me through this?