Revert i18n localization change for dynamic Pages API routes (#94905) (#97327)
### What? Partially reverts #94905 (`668cd3a4`), restoring i18n locale prefixing for **dynamic Pages API routes** in the adapter build output: ```diff -const shouldLocalize = Boolean(config.i18n) && !isAPIRoute(route.page) +const shouldLocalize = Boolean(config.i18n) ``` The middleware rewrite query fix from the same PR (`next-server.ts`, fixes #94647) is deliberately **left in place** — it is unrelated to this routing regression. Fixes #96935 ### Why? Whether `/api/...` carries a locale prefix has to be agreed on by two independent halves: 1. **this matcher** — whether the emitted dynamic route regex expects `(?<nextLocale>…)` 2. **the Vercel adapter's i18n rules** — whether they prepend `/{locale}` to `/api/...` When they disagree the matcher is unreachable and the request falls through to `/{locale}/404`. The counterpart adapter change (nextjs/adapter-vercel#81) shipped in `@vercel/next@4.21.3` on Aug 10 — roughly two months after this half landed in `v16.3.0-canary.69`. Every app in the resulting skew 404s on dynamic Pages API routes with `x-matched-path: /{locale}/404`: | | adapter beta.24 (`@vercel/next` ≤ 4.21.2) | adapter beta.25 (4.21.3) | | --- | --- | --- | | Next < `16.3.0-canary.69` |✅ |❌ | | Next ≥ `16.3.0-canary.69` |❌ |✅ | Static Pages API routes are unaffected — they resolve directly against the filesystem. `/api/echo/%5Bslug%5D` returns 200 for the same reason: it filesystem-hits the literal `[slug]` output before any i18n rule runs. Reverting this collapses the two behaviors back into one that holds for every Next.js version: dynamic Pages API routes are localized like any other dynamic route. ###⚠ ️ Must land with the adapter revert On its own, against `@vercel/next@4.21.3`, this **extends** the 404 to every Next.js version rather than fixing it. It pairs with nextjs/adapter-vercel#101 (already merged, published as `adapter-vercel@0.0.1-beta.26`), which has not yet been synced into a published `@vercel/next`. | | build container ≤ 4.21.2 / beta.26 | 4.21.3 (beta.25) | | --- | --- | --- | | with this revert |✅ all versions |❌ all versions | ### How? Removes the `!isAPIRoute(route.page)` condition and the now-unused `isAPIRoute` import, and inverts the corresponding assertion in `test/production/adapter-config-i18n` so it asserts the localized shape (`/$nextLocale/api/proxy/[[...slug]]?nxtPslug=$nxtPslug`), matching the sibling `pageRoute` assertion. A full `git revert` of `668cd3a4` was not used: the test fixture has since been renamed (`adapter-config-i18n-api` → `adapter-config-i18n`) and extended, and one of its files was renamed into an unrelated test, so a wholesale revert deletes later work. ### Verification Reproduced offline without a deployment, by running real builds of a Pages Router + i18n fixture (`/api/ping`, `/api/echo/[slug]`, `/api/users/[...path]`, `/blog/[slug]`) against both adapter versions and replaying the emitted `config.json` route tables. The replay reproduces all four reported baselines, including both off-diagonal 404s. - [x] Prettier clean on both changed files - [ ] `pnpm test test/production/adapter-config-i18n` — **not run** (needs a full `pnpm --filter=next build`); please confirm in CI Co-authored-by:Claude Opus 5 (1M context) <noreply@anthropic.com>
Showing
Please
register
or
sign in
to comment