Skip to content

Conversation

rururux
Copy link
Contributor

@rururux rururux commented Jun 28, 2025

fixes: #12850
minimal reproduction: https://stackblitz.com/edit/github-pejjugrp?file=app%2Froutes%2Fhome.tsx

While investigating the cause of this issue, I discovered an interesting behavior: removing the Content-Length header from the response results in the application functioning correctly.

Upon further examination, I found the following description in the documentation for Node.js's http module:

Set Content-Length header to limit the response body size.

In fact, when setting a clearly insufficient value such as Content-Length: 6, the response body appears to be affected accordingly.

スクリーンショット 2025-05-22 200127

スクリーンショット 2025-05-22 200153

As described in the issue, this becomes problematic when using response headers intended for redirect responses—such as those generated by authentication libraries—which often do not include a response body.
After considering how best to address this, I concluded that, regardless of whether the response is a redirect, the use of turbo-stream encoding can alter the expected body. Therefore, the most robust solution would be to remove the Content-Length header from all Single Fetch responses, which is what this PR implements.

Additional Notes:
There is a comment on the issue stating that the bug occurred in the development environment but not in production(node20, SSR enabled) . I have yet to determine the reason for this discrepancy.
Nevertheless, since I was able to reliably reproduce and fix the bug, I am submitting this pull request.

Copy link

changeset-bot bot commented Jun 28, 2025

🦋 Changeset detected

Latest commit: ab93882

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

@rururux
Copy link
Contributor Author

rururux commented Jun 28, 2025

Apologies! I accidentally messed up my previous PR #13658 and had to recreate it.
This new PR contains the intended changes.

Thanks in advance for your time and review!

@MichaelDeBoey MichaelDeBoey changed the title fix(react-router): Remove Content-Length Header from Single Fetch Responses to Prevent Errors fix(react-router): remove Content-Length header from Single Fetch responses Jun 29, 2025
@brophdawg11 brophdawg11 merged commit f4b6ef9 into remix-run:dev Jun 30, 2025
9 checks passed
@brophdawg11
Copy link
Contributor

Thanks!

@rururux
Copy link
Contributor Author

rururux commented Jul 1, 2025

Thank you for merge! 🥳

@rururux rururux deleted the content-length branch July 1, 2025 02:51
vezaynk pushed a commit to vezaynk/react-router that referenced this pull request Jul 7, 2025
Copy link
Contributor

🤖 Hello there,

We just published version 7.7.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 7.7.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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.

turbo-stream error when redirecting through an action while preserving headers
3 participants