Fix(pages-router): restore Content-Length and ETag for /_next/data/ JSON responses#90304
Merged
Merged
Conversation
vercel#90133)" This reverts commit 527ae19.
ijjk
approved these changes
Mar 18, 2026
Member
ijjk
left a comment
There was a problem hiding this comment.
Good catch, went ahead and fixed for HTML case as well and added some regression tests. Thanks for the PR!
ijjk
added a commit
that referenced
this pull request
Mar 18, 2026
…SON responses (#90304) ## What Removes the `Buffer.from()` wrapper when constructing `RenderResult` for `/_next/data/` JSON responses in the Pages Router handler. ## Why PR #80189 introduced `Buffer.from(JSON.stringify(result.value.pageData))` when building the data response. Since `RenderResult.isDynamic` checks `typeof this.response !== 'string'`, passing a `Buffer` (not a `string`) caused it to return `true`, making `sendRenderResult` treat the response as a dynamic stream — skipping `Content-Length` and `ETag` generation and falling back to `Transfer-Encoding: chunked`. This is a regression from v15.4.0 and breaks CDN-side compression for self-hosted deployments (e.g. CloudFront requires `Content-Length` to compress origin responses on-the-fly). ## Fix ```diff - Buffer.from(JSON.stringify(result.value.pageData)), + JSON.stringify(result.value.pageData), ``` ## Testing - Reproduction steps verified against the reporter's repro repo: https://github.com/bbrouse/nextjs-content-length-repro - ```diffcurl -sD - on /_next/data/<BUILD_ID>/index.json``` now returns Content-Length and ETag headers. ## Affected Area - Pages Router — /_next/data/ responses only - No impact on App Router - Single-line change, minimal blast radius Fixes #90281 --------- Co-authored-by: JJ Kasper <[email protected]> # Conflicts: # AGENTS.md
ijjk
added a commit
that referenced
this pull request
Mar 18, 2026
…xt/data/ JSON responses (#90304) (#91615) Backports #90304 Co-authored-by: Henry <[email protected]>
Contributor
|
FYI this also indirectly solved a related issue with the status code of prefetch responses and CDN caching costs. ref: #85121 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Removes the
Buffer.from()wrapper when constructingRenderResultfor/_next/data/JSON responses in the Pages Router handler.Why
PR #80189 introduced
Buffer.from(JSON.stringify(result.value.pageData))when building the data response. Since
RenderResult.isDynamiccheckstypeof this.response !== 'string', passing aBuffer(not astring)caused it to return
true, makingsendRenderResulttreat the responseas a dynamic stream — skipping
Content-LengthandETaggeneration andfalling back to
Transfer-Encoding: chunked.This is a regression from v15.4.0 and breaks CDN-side compression for
self-hosted deployments (e.g. CloudFront requires
Content-Lengthtocompress origin responses on-the-fly).
Fix
Testing
diffcurl -sD - on /_next/data/<BUILD_ID>/index.jsonnow returns Content-Length and ETag headers.Affected Area
Fixes #90281