[PR #47] [CLOSED] fix: honor has/missing conditions in next.config headers #268

Closed
opened 2026-05-06 12:38:52 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/47
Author: @ibruno
Created: 2/25/2026
Status: Closed

Base: mainHead: fix/config-headers-has-missing


📝 Commits (2)

  • a7294e1 fix: honor has/missing conditions in next.config headers
  • 27939f4 fix: apply has/missing config headers in pages-router dev

📊 Changes

11 files changed (+244 additions, -40 deletions)

View changed files

📝 packages/vinext/src/config/config-matchers.ts (+9 -0)
📝 packages/vinext/src/config/next-config.ts (+2 -0)
📝 packages/vinext/src/index.ts (+42 -26)
📝 packages/vinext/src/server/app-dev-server.ts (+9 -3)
📝 packages/vinext/src/server/prod-server.ts (+1 -1)
📝 tests/app-router.test.ts (+12 -0)
📝 tests/e2e/app-router/config-redirect.spec.ts (+11 -10)
📝 tests/fixtures/app-basic/next.config.ts (+11 -0)
📝 tests/fixtures/pages-basic/next.config.mjs (+20 -0)
📝 tests/pages-router.test.ts (+28 -0)
📝 tests/shims.test.ts (+99 -0)

📄 Description

Summary

next.config.headers() was ignoring has/missing conditions and applying headers based only on source.
This PR fixes that to align behavior with Next.js.

Changes

  • Adds has and missing support to the NextHeader type.
  • Updates matchHeaders(...) to evaluate has/missing using RequestContext.
  • Passes RequestContext in the production path (prod-server) when applying config headers.
  • Keeps dev/prod parity by updating the generated dev server path (app-dev-server).
  • Adds unit tests for matchHeaders with has/missing.
  • Adds an integration test in app-router.test.ts.
  • Enables the E2E test that was previously marked as fixme for config headers with has/missing conditions.
  • Updates tests/fixtures/app-basic/next.config.ts with has/missing header rules.

Why this matters

Without this fix, conditional headers (for example cookie-gated headers) can be applied to the wrong requests, causing incorrect behavior and a compatibility gap with Next.js.

Validation

  • pnpm run lint
  • pnpm run typecheck
  • pnpm run build
  • pnpm test
  • pnpm run test:e2e (passed; 1 test was flaky and passed on retry)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/47 **Author:** [@ibruno](https://github.com/ibruno) **Created:** 2/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/config-headers-has-missing` --- ### 📝 Commits (2) - [`a7294e1`](https://github.com/cloudflare/vinext/commit/a7294e1f5351d3b5670938b9323dbbd867f48b01) fix: honor has/missing conditions in next.config headers - [`27939f4`](https://github.com/cloudflare/vinext/commit/27939f42d754c3b05d7eb08bc663a1105c5e37a0) fix: apply has/missing config headers in pages-router dev ### 📊 Changes **11 files changed** (+244 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/config/config-matchers.ts` (+9 -0) 📝 `packages/vinext/src/config/next-config.ts` (+2 -0) 📝 `packages/vinext/src/index.ts` (+42 -26) 📝 `packages/vinext/src/server/app-dev-server.ts` (+9 -3) 📝 `packages/vinext/src/server/prod-server.ts` (+1 -1) 📝 `tests/app-router.test.ts` (+12 -0) 📝 `tests/e2e/app-router/config-redirect.spec.ts` (+11 -10) 📝 `tests/fixtures/app-basic/next.config.ts` (+11 -0) 📝 `tests/fixtures/pages-basic/next.config.mjs` (+20 -0) 📝 `tests/pages-router.test.ts` (+28 -0) 📝 `tests/shims.test.ts` (+99 -0) </details> ### 📄 Description ## Summary `next.config.headers()` was ignoring `has`/`missing` conditions and applying headers based only on `source`. This PR fixes that to align behavior with Next.js. ## Changes - Adds `has` and `missing` support to the `NextHeader` type. - Updates `matchHeaders(...)` to evaluate `has/missing` using `RequestContext`. - Passes `RequestContext` in the production path (`prod-server`) when applying config headers. - Keeps dev/prod parity by updating the generated dev server path (`app-dev-server`). - Adds unit tests for `matchHeaders` with `has/missing`. - Adds an integration test in `app-router.test.ts`. - Enables the E2E test that was previously marked as `fixme` for `config headers with has/missing conditions`. - Updates `tests/fixtures/app-basic/next.config.ts` with `has/missing` header rules. ## Why this matters Without this fix, conditional headers (for example cookie-gated headers) can be applied to the wrong requests, causing incorrect behavior and a compatibility gap with Next.js. ## Validation - `pnpm run lint` - `pnpm run typecheck` - `pnpm run build` - `pnpm test` - `pnpm run test:e2e` (passed; 1 test was flaky and passed on retry) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:38:52 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#268
No description provided.