cloudflare/vinext

Trailing slash configuration not enforced

已關閉

#1,332 建立於 2026年5月20日

 (1 則留言) (0 個反應) (0 位負責人)TypeScript (383 個分叉)github user discovery
adapter-api-e2ehelp wanted

倉庫指標

星標
 (8,624 顆星)
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

The trailingSlash configuration from next.config.js is not properly enforced in several areas:

  1. Middleware redirect Location headers ignore the config. When trailingSlash: true, NextResponse.redirect(new URL('/somewhere', req.url)) should produce Location: /somewhere/ but vinext emits Location: /somewhere.

  2. No auto-redirect for missing/extra trailing slash. Requests without trailing slash should receive a 307 redirect to the trailing-slash version (when trailingSlash: true), but vinext returns 200 with the page content directly.

  3. Shallow navigation triggers full server render. URL changes via router.push(url, undefined, { shallow: true }) cause a server roundtrip instead of a client-only URL update, detectable because the server-rendered random number changes.

Expected: "/somewhere/"
Received: "/somewhere"

Expected: 307
Received: 200

Estimated Impact

~58 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/trailing-slashes/with-trailing-slash.test.ts (20 failures)
  • test/e2e/trailing-slashes/without-trailing-slash.test.ts (20 failures)
  • test/e2e/middleware-trailing-slash/test/index.test.ts (14 failures)
  • test/e2e/app-dir/trailingslash/trailingslash.test.ts (3 failures)
  • test/e2e/basepath/trailing-slash.test.ts (1 failure)

Recommendation

  1. Reproduce first in vinext's own test suite. Add test cases that configure trailingSlash: true and verify: (a) requests without trailing slash get 307 redirected, (b) middleware redirect Location headers include trailing slash, (c) the inverse for trailingSlash: false. Confirm they fail.

  2. Study Next.js trailing slash handling. Search .nextjs-ref/packages/next/src/server/ for trailingSlash to understand where and how the normalization is applied.

  3. Apply trailing slash normalization at the server level. Before route matching, check the trailingSlash config and issue a 307 redirect if the URL doesn't conform.

  4. Normalize middleware redirect targets. When NextResponse.redirect() produces a Location header, apply the trailingSlash config to the target URL.

  5. Check dev/prod parity. Ensure both dev and production servers enforce the config consistently.

貢獻者指南