Skip to content

testing: after serveShellRequest serves a router, dispatch on the same router stops 308-redirecting a trailing-slash URL #1107

Closed

Description

@ivogt

What happens

In a unit test, after serveShellRequest has served a router, calling dispatch on the same router with a trailing-slash URL no longer answers with the 308 redirect to the canonical URL. The route matches and renders instead. A fresh router gives the expected 308.

Reproduced with a plain server route, not only with clientUrls(), so it isn't specific to client routes.

Reproduction

import { serveShellRequest, dispatch } from "@rangojs/router/testing";

const router = createRouter({ /* a route at /products */ });

await serveShellRequest(router, "/products");          // any shell request first

const res = await dispatch(router, "/products/");      // trailing slash
// expected: res.status === 308, location: /products
// actual:   the route matches and renders (200)

With a separate router for the dispatch call, the 308 is returned as expected.

Expected

dispatch behaves the same whether or not the router was served by serveShellRequest before: a trailing-slash URL redirects with 308 to the canonical URL.

Notes

  • The likely cause is per-router state that serveShellRequest sets, for example on the matcher or the trailing-slash handling, leaking into later dispatches. This isn't verified.
  • Found while extending the testing helpers to serve clientUrls() modules. The new test works around it by using a separate router for its dispatch case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions