nextjs - ✅(Solved) Fix `proxy` not working with `pageExtensions` in production builds when using `--webpack` [4 pull requests, 7 comments, 6 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#86303Fetched 2026-04-08 02:11:36
View on GitHub
Comments
7
Participants
6
Timeline
20
Reactions
4
Author
Timeline (top)
commented ×7cross-referenced ×6subscribed ×3referenced ×2

Fix Action

Fixed

PR fix notes

PR #13442: Revert Next to 15.5.2

Description (problem / solution / changelog)

Reverts Next to 15.5.2 as v16 seems to cause middleware/proxy not to run under production builds when configured to use Webpack. This meant that our CSP headers weren't getting added to the response.

Issue open with Next.js https://github.com/vercel/next.js/issues/86303

Developer Checklist

  • UX
    • UX Criteria met (visual UX & screenreader UX)
  • Accessibility
    • Accessibility Acceptance Criteria met
    • Accessibility swarm completed
    • Component Health updated
    • P1 accessibility bugs resolved
    • P2/P3 accessibility bugs planned (if not resolved)
  • Security
    • Security issues addressed
    • Threat Model updated
  • Documentation
    • Docs updated (runbook, READMEs)
  • Testing
    • Feature tested on relevant environments
  • Comms
    • Relevant parties notified of changes

Testing

  • Manual Testing required?
    • Local (Ready-For-Test, Local)
    • Test (Ready-For-Test, Test)
    • Preview (Ready-For-Test, Preview)
    • Live (Ready-For-Test, Live)
  • Manual Testing complete?
    • Local
    • Test
    • Preview
    • Live

Additional Testing Steps

  1. List the steps required to test this PR.

Useful Links

Changed files

  • .yarn/cache/@next-env-npm-15.5.2-68e002ebb4-1e1c4f5b72.zip (renamed, +0/-0)
  • .yarn/cache/@next-swc-darwin-arm64-npm-15.5.2-b38efee9bb-46b3738c0e.zip (renamed, +0/-0)
  • .yarn/cache/@next-swc-darwin-arm64-npm-16.0.1-5f5b370682-b3cd6fb829.zip (removed, +0/-0)
  • .yarn/cache/@next-swc-darwin-x64-npm-15.5.2-0ca14482f1-f266258057.zip (renamed, +0/-0)
  • .yarn/cache/@next-swc-linux-arm64-gnu-npm-15.5.2-ba9f57b4f3-a6c40e59d1.zip (renamed, +0/-0)
  • .yarn/cache/@next-swc-linux-x64-gnu-npm-15.5.2-d0fb4952a3-6158ead448.zip (added, +0/-0)
  • .yarn/cache/@next-swc-win32-arm64-msvc-npm-15.5.2-fc17d1b3e3-593dc1760f.zip (renamed, +0/-0)
  • .yarn/cache/@next-swc-win32-x64-msvc-npm-15.5.2-753dd37d77-b16645a21e.zip (renamed, +0/-0)
  • .yarn/cache/next-npm-15.5.2-9d2211c2d3-0e5a7420e7.zip (renamed, +0/-0)
  • package.json (modified, +2/-1)
  • ws-nextjs-app/middleware.page.ts (renamed, +5/-1)
  • ws-nextjs-app/next.config.js (modified, +3/-0)
  • ws-nextjs-app/package.json (modified, +15/-15)
  • yarn.lock (modified, +56/-56)

PR #13470: [DNM] Set response headers outside of Next middleware

Description (problem / solution / changelog)

Summary

Adds logic to set response headers outside of Next middleware in the event that we need to upgrade Next without a fix in place for https://github.com/vercel/next.js/issues/86303

Code Changes

  • Moves localhost rewrite of the sw.js file from middleware to next.config as it will be known at build time where its location is
  • Should behave exactly the same as it does when it was in Middleware. This is just a small optimisation to remove that processing from Middleware
  • Changes isLocal check in next.config to check against SIMORGH_APP_ENV instead of SIMORGH_PUBLIC_STATIC_ASSETS_ORIGIN
  • Adds cspHeaderResponseForNextDocumentContext function specifically for use in the _document file. This is mostly the same as the cspHeaderResponse function in the same file, but handles header setting a bit differently
  • Adds logic to _document to set the header values on getInitialProps

Developer Checklist

  • UX
    • UX Criteria met (visual UX & screenreader UX)
  • Accessibility
    • Accessibility Acceptance Criteria met
    • Accessibility swarm completed
    • Component Health updated
    • P1 accessibility bugs resolved
    • P2/P3 accessibility bugs planned (if not resolved)
  • Security
    • Security issues addressed
    • Threat Model updated
  • Documentation
    • Docs updated (runbook, READMEs)
  • Testing
    • Feature tested on relevant environments
  • Comms
    • Relevant parties notified of changes

Testing

  • Manual Testing required?
    • Local (Ready-For-Test, Local)
    • Test (Ready-For-Test, Test)
    • Preview (Ready-For-Test, Preview)
    • Live (Ready-For-Test, Live)
  • Manual Testing complete?
    • Local
    • Test
    • Preview
    • Live

Additional Testing Steps

  1. List the steps required to test this PR.

Useful Links

Changed files

  • src/app/routes/article/utils/augmentWithDisclaimer.test.ts (modified, +0/-18)
  • src/app/routes/article/utils/augmentWithDisclaimer.ts (modified, +2/-11)
  • ws-nextjs-app/middleware.page.ts (removed, +0/-42)
  • ws-nextjs-app/next.config.js (modified, +12/-2)
  • ws-nextjs-app/pages/[service]/articles/handleArticleRoute.test.ts (modified, +0/-4)
  • ws-nextjs-app/pages/[service]/articles/handleArticleRoute.ts (modified, +5/-7)
  • ws-nextjs-app/pages/[service]/live/[id]/[[...variant]].page.tsx (modified, +1/-2)
  • ws-nextjs-app/pages/[service]/send/[id]/[[...variant]].page.tsx (modified, +2/-3)
  • ws-nextjs-app/pages/[service]/watch/[id]/live/[[...variant]].page.tsx (modified, +1/-3)
  • ws-nextjs-app/pages/_document.page.tsx (modified, +49/-2)
  • ws-nextjs-app/pages/ws/languages.page.tsx (modified, +1/-4)
  • ws-nextjs-app/utilities/cspHeaderResponse/index.test.ts (modified, +67/-61)
  • ws-nextjs-app/utilities/cspHeaderResponse/index.ts (modified, +35/-43)
  • ws-nextjs-app/utilities/pageRequests/getPageData.test.ts (modified, +2/-23)
  • ws-nextjs-app/utilities/pageRequests/getPageData.ts (modified, +1/-4)

PR #14: Fix proxy file handling for custom pageExtensions in production builds

Description (problem / solution / changelog)

What?

Fixes an issue where proxy files with custom pageExtensions were not correctly routed to the edge server entrypoints in production builds with webpack. This issue arose due to the incorrect handling of proxy files in runDependingOnPageType.

Why?

This fix ensures proxy files are properly compiled as edge middleware during production builds when using custom pageExtensions, improving compatibility and behavior for edge server configurations.

How?

Removed the separate isProxyFile handling in runDependingOnPageType. This change allows proxy files to be handled through the existing isMiddlewareFile flow, ensuring correct routing to onEdgeServer().

Closes NEXT- Fixes #86303

Changed files

  • packages/next/src/build/entries.ts (modified, +0/-6)

PR #13504: Next.js toggles + common props refactor

Description (problem / solution / changelog)

Summary

Refactors toggle fetching in Next.js app to fetch in the _app.page.tsx file and pass toggles down to all page components. This saves fetching toggles multiple times for the likes of CSP header setting and for use in the page components themselves.

Moves logic to set response headers outside of Next middleware and into _app.page.tsx. This helps in the event that we need to upgrade Next without a fix in place for https://github.com/vercel/next.js/issues/86303, but mainly allows us to re-use toggles instead of fetching it twice.

Passes down various props from _app.page.tsx that are common amongst all pages so that we don't need to repeat the same logic in each getServerSideProps function.

Code changes

  • Moves localhost rewrite of the sw.js file from middleware to next.config as it will be known at build time where its location is
  • Should behave exactly the same as it does when it was in Middleware. This is just a small optimisation to remove that processing from Middleware
  • Changes isLocal check in next.config to check against SIMORGH_APP_ENV instead of SIMORGH_PUBLIC_STATIC_ASSETS_ORIGIN
  • Changes cspHeaderResponse function specifically for use in the _app file. This is mostly the same, but handles header setting a bit differently
  • Adds logic to _app to set the CSP header values on getInitialProps
  • Adds fetching of toggles to _app to allow them to be passed down to all pages as props, rather than fetching them multiple times
  • Removes isLite, isAmp, isApp, isNextJs and extractHeaders props/function from all getServerSideProps functions as these are now set globally in _app.page.tsx

Developer Checklist

  • UX
    • UX Criteria met (visual UX & screenreader UX)
  • Accessibility
    • Accessibility Acceptance Criteria met
    • Accessibility swarm completed
    • Component Health updated
    • P1 accessibility bugs resolved
    • P2/P3 accessibility bugs planned (if not resolved)
  • Security
    • Security issues addressed
    • Threat Model updated
  • Documentation
    • Docs updated (runbook, READMEs)
  • Testing
    • Feature tested on relevant environments
  • Comms
    • Relevant parties notified of changes

Testing

  • Manual Testing required?
    • Local (Ready-For-Test, Local)
    • Test (Ready-For-Test, Test)
    • Preview (Ready-For-Test, Preview)
    • Live (Ready-For-Test, Live)
  • Manual Testing complete?
    • Local
    • Test
    • Preview
    • Live

Additional Testing Steps

  1. List the steps required to test this PR.

Useful Links

Changed files

  • src/app/legacy/containers/Blocks/index.jsx (modified, +2/-1)
  • ws-nextjs-app/middleware.page.ts (removed, +0/-42)
  • ws-nextjs-app/next.config.js (modified, +12/-2)
  • ws-nextjs-app/pages/[service]/[[...]].page.tsx (modified, +0/-9)
  • ws-nextjs-app/pages/[service]/articles/augmentWithDisclaimer.test.ts (modified, +0/-20)
  • ws-nextjs-app/pages/[service]/articles/augmentWithDisclaimer.ts (modified, +2/-12)
  • ws-nextjs-app/pages/[service]/articles/handleArticleRoute.test.ts (modified, +0/-23)
  • ws-nextjs-app/pages/[service]/articles/handleArticleRoute.ts (modified, +6/-19)
  • ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.ts (modified, +1/-7)
  • ws-nextjs-app/pages/[service]/downloads/[[...variant]].page.tsx (modified, +0/-6)
  • ws-nextjs-app/pages/[service]/live/[id]/[[...variant]].page.tsx (modified, +1/-18)
  • ws-nextjs-app/pages/[service]/offline/index.page.tsx (modified, +0/-6)
  • ws-nextjs-app/pages/[service]/send/[id]/[[...variant]].page.tsx (modified, +1/-12)
  • ws-nextjs-app/pages/[service]/watch/[id]/live/[[...variant]].page.tsx (modified, +1/-8)
  • ws-nextjs-app/pages/[service]/wrapped.page.tsx (modified, +0/-3)
  • ws-nextjs-app/pages/_app.page.tsx (modified, +62/-1)
  • ws-nextjs-app/pages/ws/languages.page.tsx (modified, +1/-2)
  • ws-nextjs-app/utilities/cspHeaderResponse/index.test.ts (modified, +73/-66)
  • ws-nextjs-app/utilities/cspHeaderResponse/index.ts (modified, +38/-51)
  • ws-nextjs-app/utilities/pageRequests/getPageData.test.ts (modified, +2/-23)
  • ws-nextjs-app/utilities/pageRequests/getPageData.ts (modified, +1/-4)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:15:09 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.11.1
Relevant Packages:
  next: 16.0.2-canary.24 // Latest available version is detected (16.0.2-canary.24).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/amoore108/nextjs-proxy-pageextensions-with-webpack

To Reproduce

  1. Pull down example repo
  2. Run npm run dev
  3. Visit a page and inspect the html response headers
  4. Confirm that my-custom-header: hello is there
  5. Run npm run build
  6. Run npm run start
  7. Visit a page and inspect the html response headers
  8. Confirm that the my-custom-header is not there

Current vs. Expected behavior

Current: proxy is not running when pageExtensions is configured and a production build is ran with --webpack.

Local dev builds are fine.

Expected: proxy should run when pageExtensions is configured and a production build is ran with --webpack

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:15:09 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.11.1
Relevant Packages:
  next: 16.0.2-canary.24 // Latest available version is detected (16.0.2-canary.24).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next start (local)

Additional context

Doesn't seem to make a difference if I revert to using middleware instead of proxy, same behaviour.

Running with Turbopack seems fine, but this isn't an option for us yet.

15.5.2 version works as expected.

extent analysis

TL;DR

  • Downgrade to Next.js version 15.5.2 as a temporary workaround to resolve the issue with the proxy not running in production builds with --webpack.

Guidance

  • Verify that the issue persists when using middleware instead of proxy to confirm if the problem is specific to proxy or a broader issue with custom headers in production builds.
  • Test the application with Turbopack to see if the issue is specific to Webpack, although it's mentioned that switching to Turbopack is not currently an option.
  • Check the differences in configuration and setup between development and production environments to identify any potential discrepancies that could be causing the proxy to fail in production.
  • Consider opening an issue with the Next.js team or waiting for a future version that addresses this problem, given that version 15.5.2 works as expected but the latest version (16.0.2-canary.24) does not.

Example

No specific code example is provided as the issue seems related to the version of Next.js and its interaction with Webpack rather than a code snippet that can be easily modified.

Notes

  • The issue seems to be version-specific, given that downgrading to version 15.5.2 resolves the problem.
  • There might be underlying changes in how Next.js handles proxy or custom headers in production builds with --webpack that need to be addressed in a future update.

Recommendation

  • Apply workaround: Downgrade to version 15.5.2 until a future version of Next.js resolves the issue with proxy in production builds with --webpack, as this version is known to work as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING