Skip to content

fix(paths): type the proxy of a router with many sibling routes - #750

Open
akazwz wants to merge 1 commit into
solidjs:mainfrom
akazwz:fix/paths-many-routes
Open

akazwz wants to merge 1 commit into
solidjs:mainfrom
akazwz:fix/paths-many-routes

Conversation

@akazwz

@akazwz akazwz commented Nov 25, 2026 •

Copy link
Copy Markdown

A router with 47 or more sibling routes fails to type-check at createRouter with TS2589, "Type instantiation is excessively deep and possibly infinite". The file-system router emits one flat entry per page, so an app with about 50 pages hits it as soon as it reads paths. I found this while building an app template on @solidjs/router 2.0.1; there is no issue for it.

Root cause

TuplePaths intersected each sibling with the recursion on the rest (RouteContrib<H, PAcc> & TuplePaths<T, PAcc>). That is not a tail call, so every route nested one more instantiation until the compiler's depth limit.

Changes

TuplePaths folds the siblings into an accumulator, which makes it tail-recursive. The intersection keeps the same member order, which the PARAM_NEXT merging of sibling param calls relies on. Added a patch changeset.

Verification

  • New case in test/paths-types.spec.ts with 100 sibling routes. It fails on main with TS2589 and passes with the fix. Inline route arrays, defineRoutes and fileRoutes manifests all fail at 47 siblings on main and type-check up to at least 400 with the fix.
  • The full paths types (every call signature in order and every property, five levels deep), printed through the compiler API, are identical before and after for the existing spec routes and other shapes: sibling param prefixes in both orders, lazy children, multi-path routes, optional params, splats and fileRoutes manifests.
  • pnpm test: 762 client tests, 110 server tests and test:types pass. pnpm build passes.
  • tsc --extendedDiagnostics on tsconfig.test.json without the new case: 171,525 instantiations instead of 191,537.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b54446

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

TuplePaths intersected each sibling with the recursion on the rest, so
every route nested one more instantiation and 47 or more siblings (a flat
file-system manifest of that many pages) failed with TS2589. Folding into
an accumulator makes it tail-recursive; the member order is unchanged.
@akazwz
akazwz force-pushed the fix/paths-many-routes branch from 203fd3c to 7b54446 Compare November 25, 2026 14:34
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.

1 participant