Skip to content

fix: detect route shape collisions for API and page routes - #254

Merged
fahdfady merged 9 commits into
metacall:masterfrom
fahdfady:fix/route-shape-conflicts
Nov 16, 2026
Merged

fahdfady merged 9 commits into
metacall:masterfrom
fahdfady:fix/route-shape-conflicts

Conversation

@fahdfady

Copy link
Copy Markdown
Collaborator

Stacked on #243 (dynamic route params).

Routes are matched by shape, not by parameter names: /api/:foo and /api/:bar both match /api/42. The duplicate-route check from #228 compared literal route strings, so $foo.js + $bar.js slipped through and axum panicked at startup. Page routes have the same problem (blog/$article.tsx + blog/$slug.tsx, or a page and its own index).

Commits

  1. feat(utils) — add metassr-utils::routes with a shared DuplicateRoutesPolicy, a matchit-compatible route_shape normalizer, and a generic resolve_duplicates resolver. Also fixes a pre-existing clippy::useless_format warning in the html renderer tests.
  2. feat(pages) — validate page routes during the build (validate_page_routes, mapping source keys through setup_page_path) and resolve them in PagesHandler before registering, so a prebuilt dist cannot panic either. The API handler now re-exports the shared policy type.
  3. fix(api-handler) — route API duplicate detection through the shared resolver so parameter-name collisions are caught. Static duplicates keep the existing Error/Warn behavior.

Behavior

  • Production / metassr build: fail with every conflicting file listed.
  • Development: warn, keep the first route in deterministic order, keep running.
  • Unchanged for static duplicates (hello.js + hello.py).

Verification

  • cargo test -p metassr-utils -p metassr-api-handler -p metassr-build -p metassr-server passes (104 tests).
  • cargo clippy --workspace --all-targets -- -D warnings passes.
  • cargo fmt --all -- --check passes.
  • cargo test --workspace still fails on metassr-bundler::tests::bundling_works, which is a pre-existing environment/fixture failure unrelated to this branch (the crate is untouched).

ItsAbir005 and others added 9 commits November 4, 2026 23:28
Move duplicate route detection into metassr-utils::routes so API and
page routes can share one implementation.

The resolver groups routes by their matchit-compatible shape (for
example /api/:foo and /api/:bar both become /api/:) instead of by the
literal route string. This catches parameter-name collisions that
previously reached axum and panicked at startup. The existing Error and
Warn policies are preserved, and the result order is deterministic.

Also fixes a clippy::useless_format warning in the html renderer tests so
the workspace lints cleanly.
Page routes can collide the same way API routes do: blog/$article.tsx
and blog/$slug.tsx both match /blog/:param, and a page can also collide
with its own index file (blog/$article.tsx vs blog/$article/index.tsx).

Validate page routes during the build with the shared policy, mapping
source keys through setup_page_path so index pages and nested pages are
compared by their final route. The server also resolves page routes
before registering them, which keeps a prebuilt dist from panicking at
startup. Production fails with the conflicting files; development warns
and keeps the first route in deterministic order.

The API handler now re-exports the shared policy type so the build, the
CLI and the server all use the same enum.
Route API duplicate detection through the shared resolver, so routes are
grouped by shape instead of by their literal path. $foo.js and $bar.js
both map to /api/:param; previously they were treated as distinct and
both reached axum, which panicked during startup.

The behavior is unchanged for static duplicates (hello.js + hello.py):
production fails with every conflicting file, development warns and
keeps the first route in deterministic order. Add scanner and
registration tests for parameter-name collisions, and document that the
same rule applies to page routes.
…flicts

# Conflicts:
#	crates/metassr-build/src/server/renderer/html.rs
#	crates/metassr-server/src/handler.rs
#	docs/getting-started/folder-structure.md
@fahdfady
fahdfady merged commit 0b403ea into metacall:master Nov 16, 2026
9 checks passed
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.

2 participants