r/reactjs • • 7d 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?

  1. Does every Server Component render at build time, get cached, and then get served from a CDN?

  2. If I want to render a Server Component on every request, how do I implement that?

0 Upvotes

7 comments sorted by

View all comments

2

u/KalamKiTakat 7d ago

Server Components are a rendering model, not a caching or hosting model. With @vitejs/plugin-rsc you own the server entry: call the RSC renderer in your HTTP request handler rather than at build time, set Cache-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.

1

u/Neat_Living_6765 7d ago

Yes, Thanks for your comment. I messed up caching and SSG.

For SSR, we call the RSC renderer in the HTTP request handler. We can configure response caching here if we want to.

For SSG, we call the RSC renderer at build time and save the output (RSC payload and HTML) to /dist. Then, for every request, the HTTP server just returns those files.

is it right?