Skip to content

basePath configuration not properly scoped #1333

Description

@james-elicx

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

When basePath is configured in next.config.js, vinext does not properly enforce path scoping. Multiple sub-issues:

  1. Routes/rewrites/redirects fire without the basePath prefix. A rewrite with default basePath: true should only match paths prefixed with the basePath (e.g., /docs). vinext matches them without the prefix, so requesting /rewrite-1 returns 200 instead of 404.

  2. basePath: false external rewrites not implemented. Rewrites pointing to external URLs (https://example.com) with basePath: false should proxy the external content. vinext matches the [slug] dynamic route instead.

  3. Static assets under basePath return 404. Fetching [basePath]/_next/static/... returns 404 because the static asset layer doesn't account for the basePath prefix.

  4. basePath double-applied in asset URLs. HTML output contains /docs/docs/_next/static/... instead of /docs/_next/static/..., indicating the basePath is applied twice.

  5. Routes outside basePath not properly rejected. Requesting /hello directly (without /docs prefix) should 404 when basePath: '/docs', but vinext serves the page.

Expected: 404
Received: 200  // for /rewrite-1 without basePath prefix

Expected: "Example Domain"
Received: "...<p id=\"slug\">slug: rewrite-no-basePath</p>..."

Expected: 200
Received: 404  // for /docs/_next/static/...

Estimated Impact

~43 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/basepath/query-hash.test.ts (10 failures)
  • test/e2e/basepath/error-pages.test.ts (6 failures)
  • test/e2e/app-dir/app-basepath/index.test.ts (5 failures)
  • test/e2e/basepath/redirect-and-rewrite.test.ts (4 failures)
  • test/e2e/basepath/router-events.test.ts (4 failures)
  • test/e2e/invalid-static-asset-404-pages/*-base-path.test.ts (3 failures)
  • test/e2e/invalid-static-asset-404-app/*-base-path.test.ts (2 failures)
  • test/e2e/i18n-ignore-redirect-source-locale/redirects-with-basepath.test.ts (4 failures)
  • test/e2e/next-form/basepath/next-form-basepath.test.ts (1 failure)

Recommendation

  1. Reproduce first in vinext's own test suite. Add tests that configure basePath: '/docs' and verify: (a) routes without the prefix return 404, (b) rewrites/redirects only match with the prefix, (c) static assets serve correctly under the prefix. Confirm they fail.

  2. Study Next.js basePath implementation. Search .nextjs-ref/packages/next/src/server/ for basePath to understand how it gates request handling.

  3. Gate rewrites/redirects on basePath. When evaluating next.config.js rewrites and redirects, prepend the basePath to source patterns (unless basePath: false is set on the rule).

  4. Fix static asset serving. Strip the basePath prefix before looking up assets in the _next/static directory.

  5. Fix asset URL generation. Ensure the basePath is applied exactly once when generating <script> and <link> URLs in HTML output.

  6. Implement external URL proxying. For rewrites with basePath: false pointing to absolute URLs, proxy the request to the external origin.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions