Skip to content

fix(react-router): Remove Content-Length Header from Single Fetch Responses to Prevent Errors #13658

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

Closed
wants to merge 85 commits into from

Conversation

rururux
Copy link
Contributor

@rururux rururux commented May 22, 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 May 22, 2025

🦋 Changeset detected

Latest commit: d3dedb6

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

@remorses
Copy link
Contributor

you should remove the content length header in the redirect function instead

@rururux
Copy link
Contributor Author

rururux commented May 22, 2025

You're right that the issue tends to be most noticeable when using the redirect function.
However, the problem can occur in other cases as well, as long as Single Fetch responses are involved.
スクリーンショット 2025-05-22 205108

This is because developers typically expect the Content-Length header to reflect the size of the value they explicitly set as the response body.
But in reality, what actually gets sent is a value that has been encoded by turbo-stream, which may differ significantly from the original.
As a result, even responses that aren't redirects can end up with a mismatched Content-Length header, leading to the same kind of truncation issues.

That's why I chose to remove the Content-Length header inside the generateSingleFetchResponse function, which handles all Single Fetch responses, not just redirects.

pcattori and others added 25 commits June 3, 2025 16:44
* docs(GOVERNANCE): fix typos + grammar

* Revert a few words

---------

Co-authored-by: Brooks Lybrand <brookslybrand@gmail.com>
…13764)

Co-authored-by: Tim Dorr <timdorr@users.noreply.github.com>
Co-authored-by: Tim Dorr <timdorr@users.noreply.github.com>
Didn't realize this would be formatted. Fixing to the formatted line number.
* docs: add accessibility documentation from Remix docs

* Update docs/how-to/accessibility.md

* Update docs/how-to/accessibility.md

---------

Co-authored-by: hlimas <hlimas@ebay.com>
Co-authored-by: Brooks Lybrand <brookslybrand@gmail.com>
* Cleanup spa.md intro

* Add concurrency doc from Remix docs

* Tweak some wording
* Finish blocker doc

* Update docs/api/hooks/useBlocker.md

Co-authored-by: Michaël De Boey <info@michaeldeboey.be>

---------

Co-authored-by: Michaël De Boey <info@michaeldeboey.be>
* docs: add quick start doc for framework mode

* docs(quickstart): refine language and improve clarity in quick start guide
brophdawg11 and others added 26 commits June 27, 2025 09:43
…umentation (remix-run#13895)

* docs: add reference to meta function return types in route module documentation

* add mobregozo to contributors list
* Update react-router.config.ts

* add lazy route discovery doc

* Update react-router.config.ts.md

* Remove incorrect performance point

---------

Co-authored-by: Matt Brophy <matt@brophy.org>
@rururux
Copy link
Contributor Author

rururux commented Jun 28, 2025

uh oh.

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.