Skip to content

fix(cli): #1719 correct dynamic route segment key parsing and fail fast on multi-segment routes#1720

Open
jstockdi wants to merge 1 commit into
ProjectEvergreen:masterfrom
Battle-Creek-LLC:bug/issue-1719-dynamic-route-segment-parsing
Open

fix(cli): #1719 correct dynamic route segment key parsing and fail fast on multi-segment routes#1720
jstockdi wants to merge 1 commit into
ProjectEvergreen:masterfrom
Battle-Creek-LLC:bug/issue-1719-dynamic-route-segment-parsing

Conversation

@jstockdi

Copy link
Copy Markdown
Contributor

Related Issue

Resolves #1719

Documentation

N/A — no user-facing documentation changes. (The new fail-fast error message for multi-segment routes is self-documenting.)

Summary of Changes

  1. getDynamicSegmentsFromRoute (packages/cli/src/lib/url-utils.js): derive the segment key from the bracket in the route (/\[([^\]]+)\]/) instead of an unanchored .replace(extension, ""), so a param name that contains the extension substring (e.g. [json].js, [posts].ts) no longer produces a mangled key. [json].js now builds correctly to /alpha/index.html with params={"json":"alpha"}.
  2. Convert every bracket pair to a URL pattern segment (route.replace(/\[([^\]]+)\]/g, ":$1")) so a nested route no longer leaks a literal [..] into the URLPattern.
  3. generateGraph (packages/cli/src/lifecycles/graph.js): detect a route with more than one dynamic segment at graph build time and throw a clear, actionable error (Multiple dynamic route segments are not currently supported (found in ...). Use a single [param] per route.) instead of writing a literal [a]/ directory and then failing with an unrelated TypeError: Cannot read properties of undefined (reading 'resources').
  4. Trim the now-unused arguments passed to getDynamicSegmentsFromRoute at both call sites.
  5. Added regression tests:
    • packages/cli/test/cases/build.default.dynamic-routing-param-name-ext/ — asserts [json].js builds to /alpha/index.html with the correct params and does NOT emit a literal /[json]/ directory.
    • packages/cli/test/cases/build.default.dynamic-routing-multi-segment/ — asserts a nested [a]/[b].js route fails fast with the clear error.

Scope / follow-up

Full support for nested/multi-segment dynamic routes ([category]/[slug]) is intentionally out of scope here — it spans the graph, prerender, bundle, execute-route-module, static-router and adapters, and the single-segment.key data model would need to become multi-key throughout. This PR makes single-segment routes correct and converts the multi-segment case from a baffling crash into a clear limitation. Full nested-param support is a good follow-up enhancement.

The fail-fast check is applied to the page branch only; API routes are exempt, since they already match multiple params at runtime via URLPattern. Verified against the existing API dynamic-route specs (build.default.api, serve.dynamic-routing).

No breaking changes. Existing single-segment dynamic-route / getStaticPaths / SSR behavior is unchanged (verified against the existing dynamic-routing, getStaticPaths, and SSR specs for build, serve, and develop).

…sing and fail fast on multi-segment routes
@jstockdi jstockdi self-assigned this Jul 18, 2026
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.

Dynamic route param name containing the file extension is mis-parsed; nested routes crash unhelpfully

1 participant