fix: Cloudflare templates break when prerendering is enabled #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Description
The Cloudflare templates fail when prerendering is enabled (#31) due to incompatibility between its custom entry point and React Router Vite plugin's prerendering assumptions.
Technical Details
virtual:react-router/server-build
rollupOptions.entryFileNames
toserverBuildFile
fromreact-router.config.ts
, which prevents multiple entry points inrollupOptions.input
Solution
Fix prerendering in the Cloudflare templates by:
entryFileNames
to be[name]
to support multiple entry pointsinput
:index.js
: matches defaultserverBuildFile
React Router configurationworker.js
: matched by updatedmain = "./build/server/worker.js"
inwrangler.toml
index.js
as theserverBuildFile
inreact-router.config.ts
for clarity and discoverabilityUpdated both
cloudflare
andcloudflare-d1
templates.Proposed Long-term Fix
The React Router Vite plugin should be updated to support custom entry points for use cases like Cloudflare Workers.
Suggested Implementation
I considered leaving
entryFileNames
as the Rollup default[name].js
, but this made it harder for the developer to match theinput
entries invite.config.ts
to the file names inwrangler.toml
andreact-router.config.ts
. On the other hand, this changes Rollup's defaults and should be documented. Happy to change it back to Rollup's default and changeinput
to{index: ..., worker: ...}
if the maintainers have an opinion on this.We should probably document this feature in general anyway though.
Next Steps
entryFileNames
to be[name]
in the Cloudflare templates once the React Router Vite plugin is updated