Skip to content

fix: scope fs route middleware to each mount - #3909

Open
dvd233 wants to merge 2 commits into
freshframework:mainfrom
dvd233:fix/prefix-fsroute-middlewares
Open

dvd233 wants to merge 2 commits into
freshframework:mainfrom
dvd233:fix/prefix-fsroute-middlewares

Conversation

@dvd233

@dvd233 dvd233 commented Sep 22, 2026 •

Copy link
Copy Markdown

What changed

Scope filesystem-route middleware, layout, error, and route segments to the mount path while compiling commands. This prevents multiple fsRoutes() mounts from sharing the same root segment and ensures each mounted route keeps its own middleware chain.

Add a regression test covering three mounts of the same route tree at /, /a/foo, and /b/foo.

Why

Without the mount prefix, each _middleware.ts command is attached to the same segment. A request to the root ran the middleware once per mount. Prefixing only the middleware segment would make mounted routes lose their middleware, so route segment lookup uses the same mounted path as well.

Validation

  • Baseline probe: the root request ran the middleware 3 times.
  • Patched probe: /, /a/foo, and /b/foo each run the middleware once.
  • npx deno test -A packages/fresh/src/probe_3908_test.tsx packages/fresh/src/fs_routes_test.tsx: 57 passed, 1 ignored.
  • deno fmt --check packages/fresh/src/commands.ts packages/fresh/src/fs_routes_test.tsx: passed.
  • deno lint packages/fresh/src/commands.ts packages/fresh/src/fs_routes_test.tsx: passed.
  • deno check --allow-import packages/fresh/src/commands.ts packages/fresh/src/fs_routes_test.tsx: passed.
  • Full deno task ok reaches the formatting gate but is blocked by pre-existing formatting drift in www/static/prism.css and www/static/docsearch.css; neither file is part of this change.

Fixes #3908

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fsRoutes mounted more than once runs every _middleware once per mount

1 participant