docs/pro/react-server-components/rendering-flow.md
This document explains the rendering flow of React Server Components (RSC) in React on Rails Pro.
In a React Server Components project, there are three distinct types of bundles:
react-server condition to enable RSC-specific code paths that tell the runtime that this bundle is used for RSC payload generation.'use client' directive becomes an entry pointWhen a request is made to a page using React Server Components, the following optimized sequence occurs:
Initial Request Processing:
stream_react_component helper is called in the viewgenerateRSCPayload with the component name and propsServer-Side Rendering with RSC Payload:
RSCServerRootRSCServerRoot splits the RSC payload stream into two parts:
RSCPayloadContainer component embeds the RSC payload within the HTML responseClient Hydration:
This approach offers significant advantages:
sequenceDiagram
participant Browser
participant RailsView
participant NodeRenderer
participant RSCBundle
participant ServerBundle
Note over Browser,ServerBundle: 1. Initial Request
Browser->>RailsView: Request page
RailsView->>NodeRenderer: stream_react_component
NodeRenderer->>ServerBundle: Execute rendering request
ServerBundle->>RSCBundle: generateRSCPayload(component, props)
RSCBundle-->>ServerBundle: RSC payload with:
- Server components
- Client component refs
ServerBundle-->>NodeRenderer: Generate HTML using RSC payload
Note over Browser,ServerBundle: 2. Single Response
NodeRenderer-->>Browser: Stream HTML with embedded RSC payload
Note over Browser: 3. Client Hydration
Browser->>Browser: Process embedded RSC payload
loop For each client component
Browser->>Browser: Fetch component chunk
Browser->>Browser: Hydrate component
end
To learn more about how to render React Server Components inside client components, see React Server Components Inside Client Components.