Repository metrics
- Stars
- (8,563 stars)
- PR merge metrics
- (Avg merge 1d 1h) (462 merged PRs in 30d)
Description
This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext
mainvs Next.jsv16.2.6, 2026-05-20).
Problem
The trailingSlash configuration from next.config.js is not properly enforced in several areas:
-
Middleware redirect
Locationheaders ignore the config. WhentrailingSlash: true,NextResponse.redirect(new URL('/somewhere', req.url))should produceLocation: /somewhere/but vinext emitsLocation: /somewhere. -
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. -
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
-
Reproduce first in vinext's own test suite. Add test cases that configure
trailingSlash: trueand verify: (a) requests without trailing slash get 307 redirected, (b) middleware redirect Location headers include trailing slash, (c) the inverse fortrailingSlash: false. Confirm they fail. -
Study Next.js trailing slash handling. Search
.nextjs-ref/packages/next/src/server/fortrailingSlashto understand where and how the normalization is applied. -
Apply trailing slash normalization at the server level. Before route matching, check the
trailingSlashconfig and issue a 307 redirect if the URL doesn't conform. -
Normalize middleware redirect targets. When
NextResponse.redirect()produces a Location header, apply thetrailingSlashconfig to the target URL. -
Check dev/prod parity. Ensure both dev and production servers enforce the config consistently.