feat(react-router-serve): add DISABLE_COMPRESSION environment variable - #15339
Open
kklem0 wants to merge 1 commit into
Open
feat(react-router-serve): add DISABLE_COMPRESSION environment variable#15339kklem0 wants to merge 1 commit into
kklem0 wants to merge 1 commit into
Conversation
Skip the compression middleware when DISABLE_COMPRESSION is set to "true" or "1", for deployments where a proxy/CDN in front of the app server handles compression instead (e.g. edge caches that require an identity response with a Content-Length from the origin).
Contributor
✅ CLA SignedThanks for signing the Contributor License Agreement. |
Contributor
✅ Change File FoundOne or more change files found.
|
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.
Problem
react-router-serveunconditionally applies thecompressionmiddleware (for non-RSC builds). When the app server runs behind a CDN / edge cache that also compresses — in our case Azure Front Door — origin-side compression breaks edge caching: the origin's compressed response is chunked with noContent-Length, and when Front Door caches it, it re-serves the compressed body stamped with the uncompressedContent-Length. Clients receive a truncated body and hang waiting for the rest (we hit ~91 s stalls in production). With the origin serving identity responses, the edge compresses and caches correctly.Today the only escape hatch is the documented one: "migrate to
@react-router/express". In practice that means maintaining a full re-implementation ofcli.tsin order to remove a single middleware line — a copy that silently drifts asreact-router-serveevolves (ours already lagged behind the RSC handling and the absolute-basepublicPathfix that landed upstream since we forked it).Proposal
Support a
DISABLE_COMPRESSIONenvironment variable (trueor1) that skips thecompression()middleware:Why an env var, and why this doesn't conflict with the "no customization options by design" policy:
react-router-serve—HOSTandPORTwork exactly this way. This is deployment-environment adaptation, not server customization: the middleware itself cannot detect that a compressing cache sits in front of it.react-router-servealready treats compression as conditional: RSC builds run with compression fully disabled (disable compression for RSC responses for now #14381).Changes
packages/react-router-serve/cli.ts— skipcompression()whenDISABLE_COMPRESSIONistrue/1docs/api/other-api/serve.md— document the new env var alongsideHOST/PORTpackages/react-router-serve/.changes/minor.disable-compression-env-var.md— change fileintegration/react-router-serve-test.ts— tests asserting the default response is compressed and theDISABLE_COMPRESSION=trueresponse is identity-encoded, against the real spawned serverintegration/helpers/create-fixture.ts— allow passing extra env vars to the spawnedreact-router-serveprocess (additive optional param)Testing
pnpm build, thenplaywright test --config ./integration/playwright.config.ts react-router-serve-test— all pass, including the two new compression tests (verified across chromium/firefox/webkit/msedge projects).tscfor the serve package andprettier --checkon all touched files pass.