Repository navigation
fix(architect): base64-encode response bodies that are not valid UTF-8 - #15814
Merged
brophdawg11 merged 1 commit intoNov 23, 2026
Merged
brophdawg11 merged 1 commit into
brophdawg11 merged 1 commit into
Conversation
sendReactRouterResponse only base64-encoded bodies whose content type is an exact match in binaryTypes and read every other body with text(). Bytes that are not valid UTF-8, such as a video/mp4, image/x-icon or Image/JPEG file from a resource route, were replaced with U+FFFD before API Gateway saw them, and text() also dropped a leading byte order mark. Bodies outside the list are now decoded as fatal UTF-8 with the BOM kept, and sent as base64 with isBase64Encoded when they do not decode.
brophdawg11
approved these changes
Nov 23, 2026
brophdawg11
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the exact head. The Architect adapter preserves binary response bytes and UTF-8 byte-order marks. Regression coverage and the relevant checks passed.
Authored by an AI agent on behalf of @brophdawg11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sendReactRouterResponsein@react-router/architectsetsisBase64Encodedonly when the content type is an exact, case-sensitive match inbinaryTypes.ts. Every other body is read withawait nodeResponse.text(), so bytes that aren't valid UTF-8 become U+FFFD before API Gateway sees them.react-router/packages/react-router-architect/server.ts
Lines 118 to 127 in 9916920
So a resource route returning
video/mp4,image/x-iconorImage/JPEG(any type missing from the list, or cased differently) gets a corrupted body. The request side had the same problem, fixed in #15652.For a type that isn't in the list, this decodes the bytes with
new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }), and if that throws, sends them as base64 withisBase64Encoded: true(same check aslib/rsc/html-stream/server.ts). Listed types and valid UTF-8 bodies come out as before, with one behavior change: a leading BOM is now kept (text()stripped it). The changeset mentions it.Tests sit next to "handles resource routes with binary data": an
it.eachover the 3 types above checkingbody.equals(image)like #15652, and one over plain UTF-8 text and a BOM-led CSV.On
mainthe 3 binary cases and the BOM case fail; the plain text one passes on both:Through the built
createRequestHandler,554828.jpegsent asvideo/mp4comes back as 47,481 bytes onmainand 26,669 on the branch. Haven't tried it on a real Lambda.Architect tests 30 passed; typecheck, lint and
changes:validatepass. Fullpnpm test: the only failures arespecial-characters-test.tsxtimeouts and adata-browser-router-test.tsxhydration test that fails onmaintoo.