Skip to content

Comments

feat: add default fetch handler export for server build#14794

Open
edmundhung wants to merge 1 commit intoremix-run:devfrom
edmundhung:add-fetch-handler
Open

feat: add default fetch handler export for server build#14794
edmundhung wants to merge 1 commit intoremix-run:devfrom
edmundhung:add-fetch-handler

Conversation

@edmundhung
Copy link

Hey! It's me again 👋🏼

I've been working on improving the Cloudflare Workers setup for React Router and am wondering if there is a way to remove some of the boilerplates. Right now, Cloudflare users need a worker entry file that essentially just calls createRequestHandler and re-exports it as a { fetch } handler.

I noticed the new RSC entries already ship uncompiled source files as package exports (./config/default-rsc-entries/*) that get built by Vite, so I followed the same pattern here. This adds @react-router/dev/config/default-fetch-handler with about 12 lines that wrap createRequestHandler with the server build. Cloudflare users can then point their main directly at this export and skip the worker entry file entirely.

I'll be honest though: Cloudflare is really the main beneficiary here. It's totally fine to close if this doesn't feel worth maintaining.

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 4c150ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Major
@react-router/fs-routes Major
@react-router/remix-routes-option-adapter Major
create-react-router Major
react-router Major
react-router-dom Major
@react-router/architect Major
@react-router/cloudflare Major
@react-router/express Major
@react-router/node Major
@react-router/serve Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 10, 2026

Hi @edmundhung,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

Comment on lines +27 to +30
import { env } from "cloudflare:workers";
import type { Route } from "./+types/env";
export function loader({ context }: Route.LoaderArgs) {
return { message: context.cloudflare.env.VALUE_FROM_CLOUDFLARE };
export function loader() {
return { message: env.VALUE_FROM_CLOUDFLARE };
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using the importable env from the runtime module as the default fetch handler is runtime agnostic.

There is no context being passed through.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant