Skip to content

feat(express): add support for readable stream already closed #13992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

HenriqueLimas
Copy link
Contributor

Description

This change resolves an issue where the request body is inaccessible to react-router when a Node.js server, such as Express, uses middleware that consumes the request stream before it reaches the router's handler.

Fixes: remix-run/remix#10132

The Problem

In Node.js applications, it's common to use middleware like express.json() or express.urlencoded() to parse the request body. This process reads and consumes the request's ReadableStream.

Since Node.js streams cannot be consumed more than once (unlike the Web API's ReadableStream which can be cloned using the .tee() method), react-router is subsequently unable to read the request body. This is a frequent issue in applications that layer react-router with other Express middleware.

This PR introduces a new check to verify if the request stream has already been closed. If it has, the handler will now fallback to using the body that was already parsed and it transform it to string.

Copy link

changeset-bot bot commented Jul 15, 2025

🦋 Changeset detected

Latest commit: 5ddaa23

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/express Patch
@react-router/serve Patch
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/node Patch

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 Jul 15, 2025

Hi @HenriqueLimas,

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 [email protected].

Thanks!

- The Remix team

@HenriqueLimas HenriqueLimas force-pushed the support-closed-stream-request branch from bc802e1 to 5ddaa23 Compare July 15, 2025 00:26
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jul 15, 2025

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

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