Skip to content

fix: detect proxy.ts correctly with compound pageExtensions#93246

Open
bmorros94 wants to merge 3 commits intovercel:canaryfrom
bmorros94:fix/proxy-page-extensions-detection
Open

fix: detect proxy.ts correctly with compound pageExtensions#93246
bmorros94 wants to merge 3 commits intovercel:canaryfrom
bmorros94:fix/proxy-page-extensions-detection

Conversation

@bmorros94
Copy link
Copy Markdown

@bmorros94 bmorros94 commented Apr 25, 2026

Summary

Fixes #85648
Fixes #86303
Fixes #91600
Fixes #85646
Related to #86122
Related to #92342

When pageExtensions is set to compound extensions like ['page.ts', 'page.tsx'], proxy files must be named proxy.page.ts. However, the proxy detection logic used file_stem() (Rust/Turbopack) and path.parse().name (JS/webpack), both of which only strip the last extension — so proxy.page.ts becomes proxy.page instead of proxy, and the proxy is never detected.

Root cause: path.parse('proxy.page.ts').name returns 'proxy.page', not 'proxy'. Same issue with Rust's file_stem() which uses rsplit_once('.').

Fix: Use file_name().split('.')[0] (JS) / file_name().split('.').next() (Rust) to extract the first segment before any dot. This correctly returns 'proxy' for both proxy.ts and proxy.page.ts.

The same fileBaseName extraction is also used for middleware and instrumentation convention file detection, fixing compound pageExtensions for those as well.

Changes

  • Turbopack (Rust): crates/next-api/src/project.rs (2 locations) + crates/next-api/src/middleware.rs (1 location)
  • Webpack (JS): packages/next/src/build/index.ts (build-time detection) + packages/next/src/server/lib/router-utils/setup-dev-bundler.ts (dev-time detection)
  • E2e test: New proxy-page-extensions test suite with pageExtensions: ['page.ts', ...] and a proxy.page.ts fixture

Verified locally

Mode Bundler Result
Dev Turbopack PASS
Dev Webpack PASS
Production (build+start) Turbopack PASS
Production (build+start) Webpack PASS

Existing proxy test suites also verified (proxy-runtime-nodejs, proxy-with-middleware, proxy-missing-export, proxy-runtime) — no regressions.

Test plan

  • New e2e test proxy-page-extensions.test.ts passes in all 4 modes (dev/prod × turbopack/webpack)
  • Proxy injects x-from-proxy header and pages render through it
  • Existing proxy-runtime-nodejs tests pass (dev/webpack, dev/turbopack, production/webpack)
  • CI passes on all existing proxy tests

@github-actions github-actions Bot added tests Turbopack Related to Turbopack with Next.js. type: next labels Apr 25, 2026
@bmorros94 bmorros94 marked this pull request as ready for review April 25, 2026 19:13
@bmorros94 bmorros94 force-pushed the fix/proxy-page-extensions-detection branch from 0749169 to 22512c2 Compare April 25, 2026 19:16
When `pageExtensions` includes compound extensions like `["page.ts"]`,
the proxy file becomes `proxy.page.ts`. The existing `file_stem()` check
uses `rsplit_once('.')` which only strips the last extension, yielding
`"proxy.page"` instead of `"proxy"`, causing proxy detection to fail.

Fix: use `file_name().split('.').next()` to extract the base name before
the first dot.

Fixes vercel#85648
Ref vercel#86122
Verifies that proxy.page.ts is correctly detected and executed when
pageExtensions includes compound extensions like ["page.ts"].

Ref vercel#85648
Ref vercel#86303
Apply the same fix as the Turbopack/Rust side: use split('.')[0] instead
of path.parse().name to extract the convention file basename. Handles
compound pageExtensions like 'page.ts' where proxy.page.ts yields
path.parse().name === 'proxy.page' instead of 'proxy'.

Fixes both build-time detection (build/index.ts) and dev-time detection
(setup-dev-bundler.ts).

Fixes vercel#86303
Ref vercel#86122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment