Commit 962e5b1
Fix(pages-router): restore Content-Length and ETag for /_next/data/ JSON 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 <jj@jjsweb.site>1 parent fb85660 commit 962e5b1
3 files changed
Lines changed: 31 additions & 25 deletions
File tree
- packages/next/src/server/route-modules/pages
- test/e2e
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
152 | | - | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| |||
Lines changed: 11 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
539 | 536 | | |
540 | 537 | | |
541 | 538 | | |
| |||
740 | 737 | | |
741 | 738 | | |
742 | 739 | | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
750 | 744 | | |
751 | 745 | | |
752 | 746 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2063 | 2063 | | |
2064 | 2064 | | |
2065 | 2065 | | |
2066 | | - | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
2067 | 2070 | | |
2068 | 2071 | | |
2069 | 2072 | | |
| |||
2078 | 2081 | | |
2079 | 2082 | | |
2080 | 2083 | | |
2081 | | - | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
2082 | 2088 | | |
2083 | 2089 | | |
2084 | 2090 | | |
| |||
2135 | 2141 | | |
2136 | 2142 | | |
2137 | 2143 | | |
2138 | | - | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
2139 | 2148 | | |
2140 | 2149 | | |
2141 | 2150 | | |
| |||
2150 | 2159 | | |
2151 | 2160 | | |
2152 | 2161 | | |
2153 | | - | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
2154 | 2166 | | |
2155 | 2167 | | |
2156 | 2168 | | |
| |||
0 commit comments