Skip to content

Server route incorrect matching can break middleware #4479

Open
@alvarosevilla95

Description

@alvarosevilla95

Which project does this relate to?

Start

Describe the bug

With a structure like this:

- routes
-- status.ts <- server route
-- _app
--- route.ts
--- $id.ts

This code will compute the wrong match, as the routeTreeResult matches will be longer than serverTreeResult matches.

In the example above, if you log serverTreeResult, routeTreeResult, and matchedRoutes, you get:

  console.log(
    "serverTreeResult.matchedRoutes",
    serverTreeResult.matchedRoutes.map(r => r.id),
    serverTreeResult.matchedRoutes.length);
  console.log(
    "routeTreeResult.matchedRoutes",
    routeTreeResult.matchedRoutes.map(r => r.id),
    routeTreeResult.matchedRoutes.length
  );
  console.log("matchedRoutes", matchedRoutes.map((r) => r.id));
serverTreeResult.matchedRoutes [ '__root__', '/status' ] 2
routeTreeResult.matchedRoutes [ '__root__', '/_app', '/_app/$id' ] 3
matchedRoutes [ '__root__' ]

so middlewares are only looked for in __root, but not the actual route.

Your Example Website or App

https://github.com/alvarosevilla95/tss-bug-repros/tree/route-matches

Steps to Reproduce the Bug or Issue

  1. curl localhost:3000/status
  2. middleware logs are not emitted

Expected behavior

route is matched correctly and middlewares run

Screenshots or Videos

No response

Platform

  • Version: 1.121.27

Additional context

No response

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