fix: fail the build on fs-route configurations that would render broken pages - #178
Merged
Merged
Conversation
…en pages
File-system routing accepted several inputs that built successfully but
produced silently broken output. Validate them at build time instead:
- generateStaticParams() values must be non-empty strings without "."/".."
segments, "?", or "#"; only catch-all values may contain slashes (and no
leading/trailing/repeated ones). Anything else generated a page its own
route could never match (URLPattern matches back decoded single
segments), or wrote HTML outside the output directory via "..".
- An empty catch-all value gets a dedicated error: its zero-segment page
cannot be soft-navigated to (the live match yields no param), so a
parent-route page is suggested instead.
- nextRoutes() rejects param names URLPattern cannot express ([foo-bar]
parses as param "foo" + literal "-bar" and never matches), a param name
used twice on one route path (URLPattern construction fails, or the
inner value shadows the outer), and static directory names containing
URL-pattern metacharacters (":", "*", "?", "+", parens, braces,
backslash), which either throw at match time or match the wrong URLs.
- A page or layout module without a default export now fails the build
instead of silently rendering a blank page (or pass-through layout).
- fsRoutes.dir must be a subdirectory of the Vite root; other values
produced malformed glob patterns that matched nothing.
Also simplify FsRouteModule["default"] to a single component type (extra
union members were redundant and forced casts) and drop a stale comment
in the nextRoutes adapter.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAGg4Hh4Fmuu9ULDkdDd2
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAGg4Hh4Fmuu9ULDkdDd2
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.
Summary
An audit of the experimental file-system router found several inputs that build successfully but produce silently broken output. This PR validates them at build time with clear errors instead. Each case was verified against the real
URLPatternbehavior that@funstack/routermatches with.generateStaticParams()value validation (tree.ts)./..segments,?, or#; only catch-all values may contain slashes (and no leading, trailing, or repeated ones). Anything else generated a page its own route could never match — e.g.{ slug: "a/b" }for/blog/:slugbuildsblog/a/b.html, but:slugmatches a single segment, so the page renders broken. A..value could even write HTML outside the output directory.[5]) would never match the live key (["5"]), breaking soft navigation.Segment validation in
nextRoutes()(nextAdapter.ts)[A-Za-z0-9_$]+— what URLPattern can express.[foo-bar]was silently parsed as paramfoo+ literal-bar, producing a route that never matches its own generated pages.:,*,?,+, parens, braces, backslash), which either throw at match time (?,+) or silently match the wrong URLs.Other fixes
fsRoutes.dirmust be a subdirectory of the Vite root;.or../…values previously produced malformed glob patterns (//**/…) that matched nothing.Cleanups
FsRouteModule["default"]collapsed to a singleComponentType<FsRouteComponentProps>(the other union members were redundant under component contravariance), dropping two casts inruntime.tsx.filesByDirin the adapter.FileSystemRouting.mdxand thegenerateStaticParamsJSDoc.Test plan
pnpm typecheck,pnpm lint,pnpm format:checkcleanpnpm buildsucceeds🤖 Generated with Claude Code
https://claude.ai/code/session_01CnAGg4Hh4Fmuu9ULDkdDd2
Generated by Claude Code