workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

[[email protected]] not_found_handling SPA fallback no longer rewrites `/` when --env + inherited [[routes]] are both present

Open nocoo opened this issue 5 months ago • 2 comments

What versions & operating system are you using?

System:
  OS: macOS 26.5.1
  CPU: arm64 Apple M1 Ultra
Binaries:
  Node: 26.3.0
  npm: 11.16.0
  bun: 1.3.14
npmPackages:
  wrangler: 4.98.0 (works) vs 4.99.0 (broken)

Please provide a link to a minimal reproduction

https://github.com/nocoo/wrangler-499-spa-repro

Describe the Bug

wrangler dev with [assets] not_found_handling = "single-page-application" no longer rewrites Worker 404s on the root path / to index.html when both of the following are true:

  1. The dev session targets a named environment via --env <name>.
  2. The top-level config declares a [[routes]] block (with custom_domain = true) that is implicitly inherited by that environment. Wrangler prints the usual warning: "The 'env.test' environment inherits the top-level routes configuration … Add 'routes': [] to 'env.test' to prevent inheritance".

Under these conditions, [email protected] returns 200 with index.html for GET /, while [email protected] returns the Worker's raw 404. Non-root paths (/projects, /api/foo) behave identically across both versions — the regression is scoped to /.

Dropping either trigger (no --env, or no inherited [[routes]]) restores correct behavior on 4.99.0, so both must be present together. Locking back to [email protected] is a clean workaround.

wrangler.toml (from the repro)

name = "spa-repro"
main = "src/index.ts"
compatibility_date = "2026-04-01"

[dev]
port = 18099

[assets]
directory = "./dist/client"
binding = "ASSETS"
run_worker_first = ["/api/*"]
not_found_handling = "single-page-application"

[[routes]]
pattern = "spa-repro.example.com"
custom_domain = true

[env.test]

Worker (the Worker intentionally returns 404 for non-/api/* so the assets handler must rewrite)

export default {
  async fetch(req: Request): Promise<Response> {
    const url = new URL(req.url);
    if (url.pathname.startsWith("/api/")) {
      return new Response(JSON.stringify({ ok: true, path: url.pathname }), {
        headers: { "content-type": "application/json" },
      });
    }
    return new Response("worker 404", { status: 404 });
  },
};

Probe

Version Command GET / GET /projects GET /api/live
4.98.0 wrangler dev --env test --port 18099 200 <!doctype html> 200 <!doctype html> 200 JSON
4.99.0 wrangler dev --env test --port 18099 404 worker 404 200 <!doctype html> 200 JSON

If you drop the top-level [[routes]] block (so the inheritance warning goes away), 4.99.0 also returns 200 on /. If you drop --env test, 4.99.0 also returns 200 on /. The bug requires both triggers together.

Real-world impact

Discovered while upgrading cloudflare/dove from [email protected] to 4.99.0: the L3 Playwright suite's page.goto("/") then started seeing 404 Not Found only on the dashboard root. Bisect across our dep-bump commits + direct curl probing of the dev server isolated this to wrangler 4.99.0; the upgrade was held back as a result.

Please provide any relevant error logs

wrangler dev itself prints no error — the Worker simply receives GET / and returns 404, which the assets layer no longer rewrites under the trigger conditions above. The inheritance warning is shown at startup but is unrelated to the regression itself (it was emitted by 4.98.0 too).

nocoo avatar Jun 11 '26 06:06 nocoo

This also happens with not_found_handling of 404-page.

valtlai avatar Jun 11 '26 16:06 valtlai

Sorry about this! working on a fix - in the meantime 4.98.0 does not have this issue.

emily-shen avatar Jun 11 '26 16:06 emily-shen