Repository navigation
fix: detect route shape collisions for API and page routes - #254
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #243 (dynamic route params).
Routes are matched by shape, not by parameter names:
/api/:fooand/api/:barboth match/api/42. The duplicate-route check from #228 compared literal route strings, so$foo.js+$bar.jsslipped through and axum panicked at startup. Page routes have the same problem (blog/$article.tsx+blog/$slug.tsx, or a page and its ownindex).Commits
feat(utils)— addmetassr-utils::routeswith a sharedDuplicateRoutesPolicy, a matchit-compatibleroute_shapenormalizer, and a genericresolve_duplicatesresolver. Also fixes a pre-existingclippy::useless_formatwarning in the html renderer tests.feat(pages)— validate page routes during the build (validate_page_routes, mapping source keys throughsetup_page_path) and resolve them inPagesHandlerbefore registering, so a prebuiltdistcannot panic either. The API handler now re-exports the shared policy type.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
metassr build: fail with every conflicting file listed.hello.js+hello.py).Verification
cargo test -p metassr-utils -p metassr-api-handler -p metassr-build -p metassr-serverpasses (104 tests).cargo clippy --workspace --all-targets -- -D warningspasses.cargo fmt --all -- --checkpasses.cargo test --workspacestill fails onmetassr-bundler::tests::bundling_works, which is a pre-existing environment/fixture failure unrelated to this branch (the crate is untouched).