RFC: Prerendering with Vite Preview Server #14651
Replies: 1 comment
-
|
I'd like to share my use case that would benefit from this feature. My Setup
The ProblemWith // Option 1: Simple flag
prerender: true,
// Option 2: Explicit paths
async prerender() {
return [
'/',
'/posts',
'/projects',
'/bookmarks',
'/about',
...(await mdx.paths()),
];
},Regardless of This is the same issue described in #14096. Workaround AttemptI also tried the workaround from #13226 (adding export default defineConfig(({ isSsrBuild }) => ({
build: {
rollupOptions: isSsrBuild
? { input: ['virtual:react-router/server-build'] }
: undefined,
},
plugins: [reactRouter(), tsconfigPaths(), netlifyReactRouter(), netlify()],
}));This still fails with the same error — the Netlify plugin appears to override or conflict with the rollup configuration. Why This MattersI had to disable prerender entirely and rely on SSR-only, which means every request hits Netlify Functions instead of serving static HTML. For a blog with mostly static content (MDX files), prerendering would significantly improve performance and reduce serverless function invocations. The proposed solution of using Vite preview server elegantly decouples the build environment from the deployment runtime. Looking forward to this landing! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
React Router's current prerendering directly imports the server bundle:
This requires the build runtime to match the deployment runtime if your code imports runtime-specific modules.
For example, when building with Node.js for Cloudflare Workers deployment, prerendering fails because Node.js can't import
"cloudflare:workers"modules. You can't run the build in the Workers runtime either, since it doesn't support running Vite.Proposed Solution
Use Vite's preview server instead of directly importing the server bundle.
This decouples the build environment from the target runtime:
No API changes - prerendering continues to work the same way from a user perspective. But we can start with an unstable flag for the community to test:
Benefits
Implementation
Full implementation PR available at: #14650
Main changes:
Trade-offs
vite previewsupport #14507)Beta Was this translation helpful? Give feedback.
All reactions