fix(headers): strip internal dev request ID headers#2260
Conversation
|
/bigbonk review for issues |
There was a problem hiding this comment.
Review: LGTM
This is a clean, well-scoped fix that faithfully mirrors the upstream Next.js change in vercel/next.js#94703.
What I verified
- Constant values match upstream exactly.
NEXT_REQUEST_ID_HEADER(x-nextjs-request-id) andNEXT_HTML_REQUEST_ID_HEADER(x-nextjs-html-request-id) match the values inpackages/next/src/client/components/app-router-headers.ts. - Correct chokepoint.
_getReadonlyHeadersis the single source for theheaders()userland view across both routers (it's the only caller of_sealHeadersfor request headers), so stripping here covers all paths. Pages and App Router both flow through it. - Raw headers preserved. The fix copies into a fresh
new Headers(ctx.headers)before deleting, soctx.headersstays intact for internal reads — the test asserts this, matching the upstream comment that "the server reads them from the raw request headers, not from here." - Cache invalidation is safe.
applyMiddlewareRequestHeadersnullsctx.readonlyHeaderson a middleware override (headers.ts:540), so the stripped copy is rebuilt correctly afterNextResponse.next({ request: { headers } }). - Tests pass. Ran
vp test run tests/shims.test.ts -t "next/headers shim"(33 passed) and the new regression test in isolation (passes).
Note (non-blocking)
The PR title/description frame this as stripping only the dev request-id headers, but the change also now strips FLIGHT_HEADERS (rsc, next-router-state-tree, etc.) from the userland headers() view — and the test asserts that (expect(h.get("rsc")).toBeNull()). This is the correct behavior and matches upstream's getHeaders in request-store.ts, and flight headers are already stripped at the middleware boundary via requestWithoutFlightHeaders in server/app-middleware.ts, so this is sound defense-in-depth. Just worth noting the diff does slightly more than the title suggests.
No changes requested.
|
Review posted. Summary of my findings on PR #2260: Verdict: LGTM (approved) The PR is a clean, well-scoped fix that faithfully mirrors upstream Next.js #94703. What I verified:
One non-blocking note flagged: the diff also strips |
commit: |
Performance benchmarksCompared 1 improved · 0 regressed · 5 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
Close #1934
Summary
x-nextjs-request-idandx-nextjs-html-request-idfrom the read-onlyheaders()view exposed to userland.headers()vercel/next.js#94703.Verification
pnpm test tests/shims.test.ts -t "headers\\(\\) strips internal flight and dev request-id headers"pnpm test tests/shims.test.ts -t "next/headers shim"pnpm exec vp fmt --check packages/vinext/src/server/headers.ts packages/vinext/src/shims/headers.ts tests/shims.test.ts