Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix(pages-router): restore Content-Length and ETag for /_next/data/ JSON responses#90304

Merged
ijjk merged 10 commits into
vercel:canaryfrom
lllomh:fix/pages-data-content-length-90281
Mar 18, 2026
Merged

Fix(pages-router): restore Content-Length and ETag for /_next/data/ JSON responses#90304
ijjk merged 10 commits into
vercel:canaryfrom
lllomh:fix/pages-data-content-length-90281

Conversation

@lllomh
Copy link
Copy Markdown
Contributor

@lllomh lllomh commented Feb 21, 2026

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

- Buffer.from(JSON.stringify(result.value.pageData)),
+ JSON.stringify(result.value.pageData),

Testing

Affected Area

  • Pages Router — /_next/data/ responses only
  • No impact on App Router
  • Single-line change, minimal blast radius

Fixes #90281

@vercel vercel deleted a comment from nextjs-bot Mar 18, 2026
@vercel vercel deleted a comment from nextjs-bot Mar 18, 2026
@vercel vercel deleted a comment from nextjs-bot Mar 18, 2026
@vercel vercel deleted a comment from nextjs-bot Mar 18, 2026
@vercel vercel deleted a comment from nextjs-bot Mar 18, 2026
Copy link
Copy Markdown
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, went ahead and fixed for HTML case as well and added some regression tests. Thanks for the PR!

@ijjk ijjk merged commit 962e5b1 into vercel:canary Mar 18, 2026
265 of 271 checks passed
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
@iiegor
Copy link
Copy Markdown
Contributor

iiegor commented Mar 24, 2026

FYI this also indirectly solved a related issue with the status code of prefetch responses and CDN caching costs.

ref: #85121

@github-actions github-actions Bot added the locked label Apr 8, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/_next/data/ responses missing Content-Length header since v15.4.1 (Pages Router, self-hosted behind CDN)

4 participants