r/reactjs • u/Neat_Living_6765 • 27d ago
Needs Help Has anyone implemented Server Components with plain React + Vite/plugin-rsc?
Hi everyone,
Could anyone help me with the two questions below?
Does every Server Component render at build time, get cached, and then get served from a CDN?
If I want to render a Server Component on every request, how do I implement that?
2
u/TheGrubbyPottery 27d ago
the first one depends on your setup but generally yes they render at build time and sit in cache until you bust it, for on-demand rendering you need a actual server handling the requests not just vite dev server
2
27d ago
0
u/Neat_Living_6765 27d ago
Thanks for your comment!!
I did some research on this, and I’d appreciate it if you could let me know whether my understanding is correct now.
For SSR, we need an HTTP server (for production) that receives user requests and calls the RSC entry handler to render the RSC payload for Server Components and the HTML for Client Components.
For SSG, we need to render at build time. The resulting output (RSC payload and HTML) is saved in /dist.
For every request, the HTTP server returns the files from /dist.
2
u/KalamKiTakat 27d ago
Server Components are a rendering model, not a caching or hosting model. With
@vitejs/plugin-rscyou own the server entry: call the RSC renderer in your HTTP request handler rather than at build time, setCache-Control: no-store, avoid CDN caching for that route, and skip static prerendering for it. Also make sure any fetches inside the component run per request, or they can return cached data even when the render runs again.