cloudflare/vinext

i18n routing: `locale: false` on rewrites/redirects not implemented

已关闭

#1,336 创建于 2026年5月20日

 (1 条评论) (0 个反应) (0 位负责人)TypeScript (371 个派生)github user discovery
adapter-api-e2ehelp wanted

仓库指标

星标
 (8,563 个星标)
PR 合并指标
 (平均合并 1天 1小时) (30 天内合并 462 个 PR)

描述

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-20).

Problem

Several i18n routing features are not properly implemented:

  1. locale: false on rewrite/redirect sources not implemented. When a rewrite or redirect in next.config.js specifies locale: false on the source, the pattern should match the raw path without locale prefix handling. vinext does not honor this flag, so rewrites/redirects fail to match when they should.

  2. Locale detection re-runs on every request instead of being sticky. After the initial locale is established, client-side navigations should preserve it. vinext appears to re-detect from Accept-Language on each server request, causing the locale to flip unexpectedly.

  3. Locale prefix not stripped for API routes. Requests like /fr/api/ok need the locale prefix stripped before API route matching. vinext does not strip it, causing 404s.

  4. Default locale prefix stripping missing. Requests to /en/page (where en is the default locale) should redirect to /page. This redirect is not happening.

Expected: "en"
Received: "id"  // locale flipped to browser preference on client nav

Estimated Impact

~24 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/i18n-ignore-rewrite-source-locale/rewrites.test.ts (8 failures, all 8 tests)
  • test/e2e/i18n-ignore-redirect-source-locale/redirects-with-basepath.test.ts (4 failures)
  • test/e2e/i18n-ignore-redirect-source-locale/redirects.test.ts (4 failures)
  • test/e2e/ignore-invalid-popstateevent/with-i18n.test.ts (3 failures)
  • test/e2e/ignore-invalid-popstateevent/without-i18n.test.ts (2 failures)
  • test/e2e/i18n-preferred-locale-detection/i18n-preferred-locale-detection.test.ts (1 failure)
  • test/e2e/i18n-default-locale-redirect/i18n-default-locale-redirect.test.ts (1 failure)
  • test/e2e/middleware-custom-matchers-i18n/test/index.test.ts (1 failure)

Recommendation

  1. Reproduce first in vinext's own test suite. Add tests for: (a) a rewrite with locale: false source matching a non-locale-prefixed path, (b) locale persistence across client navigations, (c) API routes under locale prefixes. Confirm they fail.

  2. Study Next.js i18n implementation. Search .nextjs-ref/packages/next/src/server/ for locale: false, locale detection, and locale stripping logic.

  3. Implement locale: false flag. When evaluating rewrite/redirect sources with locale: false, skip the locale prefix injection and match against the raw path.

  4. Make locale detection sticky. Once a locale is established (either by URL prefix or initial detection), it should be preserved across navigations. The locale context should be carried in the client-side router state.

  5. Strip locale prefix for API routes. Add locale stripping before the API route matching step.

贡献者指南