Skip to content

Support React Server Components #9089

Open

Description

@slorber

Discussed in #8758

Originally posted by gaearon March 10, 2023

CleanShot 2023-06-21 at 19 58 36@2x

I'd like to start a discussion on what it would take to get full RSC support in Docusaurus.

I imagine there could be different "layers" where support could be added, probably independent from each other:

  • Support for writing Pages as RSC.
  • Support for treating MDX as RSC by default.
  • Porting the core of the site to RSC.

This isn't super scientific but gives some anecdotal evidence that it's worth at least experimenting with:

Screenshot 2023-03-10 at 18 01 08

It also seems like a more scoped project than adopting RSC in a framework because Docusaurus is already constrained (always static output, no complex layouts).

Would love to hear your thoughts (and also happy to answer any integration questions).

Activity

  1. slorber commented on Jun 21, 2023

    @slorber
    CollaboratorAuthor

    My initial answer:


    Hey 👋

    Actually, I've been thinking about this a lot and definitely want to add RSC support in Docusaurus for various reasons.

    One of them is of course to reduce the bundle size, hydration time (particularly on long MDX content that's often quite static) and improve Lighthouse/CWV metrics.

    There are also opportunities to use RSC to use more convenient tooling to interleave heavy runtime libs without paying the cost in the bundle. I'm thinking of:

    Some related tweets:


    What I'm most excited about is the flexibility it allows for Docusaurus Server/Static Components to query a data lake. We currently don't have a data layer like Gatsby, so the blog data is kind of only available on the /blog/* routes. With RSC we could query a big object DB and easily inject things like the 3 latest blog posts on your landing page.

    Somehow it would allow the same as GraphQL for Gatsby, but we'd only use TypeScript instead and just pick the data we want for each page through the Server Components.


    Today I'm still in the process of upgrading to MDX 2 (#8288) and will upgrade to React 18 just after 😅 Also apart from looking at Next.js I'm not sure yet how to integrate RSCs in Docusaurus, is there any example of vanilla RSC integration out there?

  2. added
    proposal
    on Jun 22, 2023
  3. thedevwonder commented on Jun 30, 2023

    @thedevwonder
    Contributor

    This looks like a good thing for experimentation. I don't have much experience on server-side react but would definitely like to try it out!

  4. usulpro commented on Oct 2, 2024

    @usulpro

    Hey there! RSC seems like a solid way to boost performance. It’d be awesome to have this available for both pages and custom plugins. Could you share an update on where things stand with this feature now?

  5. slorber commented on Oct 2, 2024

    @slorber
    CollaboratorAuthor

    Hey there! RSC seems like a solid way to boost performance. It’d be awesome to have this available for both pages and custom plugins. Could you share an update on where things stand with this feature now?

    @usulpro the work on RSC hasn't started yet.

    But we are in the process of migrating to Rspack (#10402) and made good progress on that, it should be released as experimental in v3.6 as a replacement for Webpack building 3x faster.

    Adopting Rspack is an important step because adopting RSCs under Webpack might also slow down the build, which was already quite slow. Rspack (and other modern module bundlers) now have the ability to build the same app in multiple variants (Node, Client, RSC...) in a single pass instead of using Webpack MultiCompiler:

    https://rspack.dev/blog/announcing-1-0#react-server-components-support

    So, the first step is successfully adopting Rspack. Then we'll work on RSC support. But it's likely to take some time and require significant refactor of how our theme is organized. Some of our theme components will have to become RSCs for example, while others will use "use client". Most likely we'll refactor this progressively and start by adding "use client" everywhere to release RSC support sooner.

  6. SyMind commented on Mar 27, 2026

    @SyMind

    Hi @slorber, Rspack now has built-in RSC capabilities: https://v2.rspack.rs/guide/tech/rsc

    You can find usage examples here: https://github.com/rstackjs/rspack-rsc-examples

    If needed, I'd be happy to provide any help with the RSC integration.

  7. slorber commented on Mar 30, 2026

    @slorber
    CollaboratorAuthor

    Thanks :) We'll look into this after Docusaurus v4 is out, and see if we can have an RSC-based version for Docusaurus v5.

    I guess it could also be easier to add RSC support if we first drop support for Webpack, which we'll still support in v4, right? Or do you think Webpack/Rspack abstractions are similar enough to make it relatively easy to support both bundlers?

    Is it possible to only have 2 entries? IMHO since we are an SSG, we don't really need the same setup as frameworks that support SSR, and maybe we don't need 2 layers for SSR/RSC?. Does it make sense? I wonder what Rspress is doing BTW.

  8. SyMind commented on Mar 31, 2026

    @SyMind

    I guess it could also be easier to add RSC support if we first drop support for Webpack, which we'll still support in v4, right? Or do you think Webpack/Rspack abstractions are similar enough to make it relatively easy to support both bundlers?

    Regarding Webpack: Rspack's current RSC solution does not support Webpack out of the box. If we wanted to support RSC in Webpack as well, we would essentially have to build the integration for Webpack from scratch. So yes, dropping Webpack first would definitely make adopting RSC much easier.

    Is it possible to only have 2 entries?

    To support RSC builds, Rspack fundamentally needs to spin up two separate Compilers: one to build the server-side artifacts (for Node execution) and another to build the client-side artifacts (for browser execution). Because of this underlying architecture, Rspack requires a minimum of two entries—one for the Server Compiler and one for the Client Compiler.

    IMHO since we are an SSG, we don't really need the same setup as frameworks that support SSR, and maybe we don't need 2 layers for SSR/RSC?. Does it make sense?

    Even in an SSG context, the two layers setup is still necessary during the build step.

    Here is why: within the Server Compiler, the process of executing React Components -> RSC payload relies specifically on the React react-server runtime. However, the subsequent step of rendering that RSC payload -> HTML String relies on the default React runtime. To handle both of these steps correctly within the same build process, we have to configure different resolve conditions, which requires separating them into two distinct layers.

  9. slorber commented on Mar 31, 2026

    @slorber
    CollaboratorAuthor

    Thanks, I understand

    We already have 2 entries (client/brower + node/server/ssg). I thought that we needed to build our app in 3 variants to support RSC, and that seemed overkill for SSG.

    https://green.sapphi.red/blog/increasing-vites-potential-with-the-environment-api

    Second, a single application now needs to handle multiple bundles. At the end of 2020, React Server Components were announced: to use React Server Components, you will need a bundle for RSC, separate from the client bundle for the browser and the SSR bundle for doing SSR. This means that up to three different bundles need to be handled.

    From what I understand, it's possible to separate the SSR server and the RSC flight server, eventually host them in different places too, but it's not mandatory. In your example it seems that the "server" app handles both ssr/rsc and a single server can handle requests for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions