Description
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):
- Identify all static routes from the React Router config.
- Render each route to HTML using a static rendering utility (e.g.,
react-dom/server
withStaticRouter
). - 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.