feat(express): add support for readable stream already closed#13992
feat(express): add support for readable stream already closed#13992HenriqueLimas wants to merge 1 commit intoremix-run:devfrom
Conversation
🦋 Changeset detectedLatest commit: 5ddaa23 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
|
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 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 |
bc802e1 to
5ddaa23
Compare
|
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
Description
This change resolves an issue where the request body is inaccessible to
react-routerwhen 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()orexpress.urlencoded()to parse the request body. This process reads and consumes the request'sReadableStream.Since Node.js streams cannot be consumed more than once (unlike the Web API's
ReadableStreamwhich can be cloned using the.tee()method),react-routeris subsequently unable to read the request body. This is a frequent issue in applications that layerreact-routerwith 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.