Skip to content

[Feature] Add Static Pre-rendering Capability to rsbuild-plugin-react-router #6

Open
@kziemski

Description

@kziemski

Description:
Add support for static pre-rendering to the rsbuild-plugin-react-router plugin, enabling generation of static HTML files for React Router routes at build time.

Motivation:
Static pre-rendering improves initial page load performance and SEO by serving pre-rendered HTML instead of relying on client-side rendering. According to the React Router documentation on static pre-rendering, this is a recommended approach for frameworks using React Router. This feature would align the plugin with modern web development practices and enhance its utility for static site generation use cases.

Proposed Solution:

  • Integrate a static pre-rendering step into the Rsbuild pipeline, leveraging React Router’s route configuration.
  • Use a strategy similar to React Router’s static rendering example: crawl the route tree and render each route to HTML during the build process.
  • Output static HTML files to the build directory (e.g., dist/), alongside the client-side bundle.
  • Potentially expose a configuration option in the plugin to enable/disable static pre-rendering or specify routes to pre-render.

Example Workflow (based on React Router docs):

  1. Identify all static routes from the React Router config.
  2. Render each route to HTML using a static rendering utility (e.g., react-dom/server with StaticRouter).
  3. Write the rendered HTML to disk during the Rsbuild process.

Status:
This is a placeholder issue—implementation details and feasibility within Rsbuild/Rspack need further exploration.

Open Questions:

  • How should the plugin integrate with Rsbuild’s existing build pipeline?
  • Should pre-rendering be opt-in via config, or enabled by default?
  • Are there specific React Router features (e.g., dynamic routes) that need special handling?
  • What performance considerations should be addressed for large route trees?

References:

Feedback welcome! Let me know if this aligns with the plugin’s goals or if additional scoping is needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions