0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00

Compare commits

...

44 commits

Author SHA1 Message Date
autofix-ci[bot]
250fbbdfe5
ci: apply automated fixes 2026-11-11 14:21:31 +00:00
Manuel Schiller
ad7651bf64 chore(pnpm): regenerate the lockfile after rebasing on main
Merging the lockfiles of main and the route-modules commits left it
inconsistent. Regenerate it with pnpm 12 from the pre-rebase lockfile,
so every importer, including the route-modules fixtures, keeps one Vite
with the Start packages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:17:43 +01:00
Manuel Schiller
ff04889642 docs(route-modules): state the mask rule and the Start validation limits
A mask is built in the scope of its destination. Start requirements cannot be
certified by `any` or `never` fields, a route's `server.middleware` list is
not validated against them, and a module's own fragment context is not
protected against later modules.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
e086b4e1b3 chore(e2e): declare vite for the route-modules fixture tests
Two fixture tests import vite, which only resolved through the repository
root.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
ac7eee1341 chore(route-modules): include the stand-ins in the example and benchmark builds
The large example's modules and the benchmark's modules use other modules;
their declaration builds now include `.tanstack/route-types-stubs.d.ts` as
documented, so they need no order among the modules. The example ignores the
generated namespace files and client views.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
efac4fd522 test(start): compile the team module's declarations against the stand-ins
The react-start fixture's team module uses settings but built its
declarations against the real contract, relying on publish order. Its
declaration build now includes the generated stand-ins like the react-router
fixture, so the probe for a used module's local paths moved to the source
check, which reads the real contract.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
cdf5f5801c test(route-modules): sharpen the fixture assertions
The tree-shaking check listed six APIs that have no binder and never asserted
that the names it looks for exist; it now lists the bound APIs and requires
the Link binder in the Link bundle. The validation alias type tests pass the
foreign value to the alias instead of a mismatching literal. The header
variants assert the generated headers. Two assertions that could not fail
are gone. The suites share their check and emit expectations, content hashes
come from the workspace, and the declaration build against the real contracts
is one helper.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
19b50ad1dc perf(router-core): read module scopes only behind the route-module binding
The mask-scope check hoisted a read of the options' scope above the binding
condition, which kept 27 bytes of it in every application bundle. Both reads
sit inside the conditions again, so applications without route modules drop
them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
f923c4fe52 test(start): define the route-module build test once for the three frameworks
The React, Solid and Vue Start packages ran the same 370-line fixture with
six differing constants; the fixture now lives in start-plugin-core's tests
and each package defines it for its own plugins.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
e913583529 perf(start-client-core): skip module validation without module requirements
Applications that register no route-module requirement no longer walk their
local middleware chains at every `.server()` and `.handler()`; the installed
ids of a module list are computed once instead of once per required module;
the consumer id and middleware-owner unions are spelled once.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
dc72efd448 fix(start-client-core): an any or never field cannot certify a requirement
The context validation rejected a whole `any` context but accepted a required
field typed `any` or `never`, since both are assignable to the requirement.
Such fields are now reported, at the application and before a local consumer.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
fee0cd3d67 fix(vue-router): accept object scopes on MatchRoute
A scoped `MatchRoute` can receive options whose scope is resolved later, an
object rather than a module id; the prop no longer warns about it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
924b3ffdfd refactor(route-modules): bind id-based scope APIs through one core helper
The eight id-based binders (`getRouteApi`, `useMatch`, `useLoaderData`,
`useLoaderDeps`, `useSearch`, `useParams`, `useRouteContext`, `notFound`) were
spelled out in each framework; they now delegate to one core helper that maps
module-local ids to the installation. The unused `FileRoutesByPathEntry` type
is dropped.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
a49e5e5a06 fix(solid-router): keep each prop of a scoped component reactive
Scoped `Link`, `createLink`, `Navigate` and `MatchRoute` spread their props
proxy to add the module scope. Solid resolves such a spread in one memo, so
every prop, children included, depended on every other: a params change
re-created the children and replaced the element. The scope is now merged as
a lazy getter over the props, as the scoped `useLinkProps` already did, with
the core's scope resolution exported for it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
1f6865579d fix(router-core): type the module id of the installation diagnostic
The id is set once the options or their mask carry a scope, which the
preceding check establishes; the build did not see that.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
f1db26ad1d refactor(start-plugin-core): share the server-only route predicate
The generator's pruning and Start's client tree each spelled out when a
route has only a `server` option; the generator now exports the predicate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
96370df148 perf(start-plugin-core): resolve client views only with mounted modules
The Vite client plugin resolved every relative import a second time to look
for a mounted module's route tree, and the Rspack replacement hook ran for
every module; both now return early while no module has a client view. The
Rspack transform resolves the generated route tree path once.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
06e04a78ff refactor(router-plugin): one watcher setup for webpack and Rspack
The two compiler hooks were identical apart from webpack's completion log.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
e296bde059 fix(router-plugin): prefer the generated route id in webpack HMR statements
The webpack adapter read the id of the uninitialized replacement Route first:
a module root (and a file route before its parent is assigned) reads as a root,
so the hot update patched the application root with the module root's options.
The generated id now comes first, hot data second, as in the Vite adapter.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
a048cf574e fix(router-plugin): compile module roots like root routes
A route module's root is created with `createModuleRoot()({ ... })` from the
module's generated scope. The code splitter's file filter and its root-route
list did not know the factory, so module roots never got an HMR statement, and
Start client builds kept their `ssr`, `server` and `headers` options with their
server-only imports.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
b7489bbff2 perf(router-core): keep options already bound to their scope
`bindRouteScopeOptions` returns the options unchanged when they already carry
the scope they are bound to, instead of copying them on every scoped link
build.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
6e20efc8aa fix(router-core): name a single named installation in its diagnostic
Addressing a module by its id when its only installation is named said the
module was installed several times. The development message now lists the
installation names.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
c0368e128e perf(router-core): resolve a not-found target once on the client
The client not-found boundary resolved the module-local target id inside
`findIndex`, once per match; it now resolves it once like the server lane.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:25 +01:00
Manuel Schiller
0caab449ba fix(router-core): build a location's mask in the scope of its destination
A module-scoped mask on an application destination (`settings.linkOptions`
as the `mask` of an application `Link`) type-checks but was resolved as an
application path. It is now rejected in development like a mask from another
module on a module destination, through the same scope resolution, which no
longer allocates an options copy for the check.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
5cdbf908ad fix(router-core): reject mounting a module root with and without a name
A module is installed once, or several times under names. Mounting the same
root unnamed and then named reinitialized the unnamed installation against
the template host, so its routes no longer matched; the reverse order made
module-local ids resolve to the unnamed copy. `mountRouteModule` now rejects
the mix the way the generator does, while mounting the same installation
again, as hot updates do, stays allowed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
ef219d3b23 refactor(route-modules): one core binding for the route-module behavior
The core keeps the route-module behavior (module-root id, id resolution,
location scoping, navigation scope) in one never-assigned `routeModules`
binding instead of four; every read site branches on that one binding, so
applications without route modules still drop it entirely. Module roots and
mounts install it: the module-root factory of a generated scope installs the
core behavior and the framework's link options when the root is created, and
`mountRouteModule` installs the core behavior. Binding a scope API or building
options installs nothing anymore, so every generated `/* @__PURE__ */` binder
call is pure. A module option built without any installed module is named in
development; production keeps no check.

Adopts the binding and binder parts of TanStack/router#8845 without the
`createRouteModuleRouter` factory.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
90c28e6fa4 docs(route-modules): document linking in both directions
The stand-in include of the declaration build, `uses` through namespaces in
both directions, the generated files table and the Nx and Turborepo task
wiring for used modules.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
461688ca13 test(route-modules): cover linking in both directions in the react-router fixture
products uses account and storefront, account uses products, through peer
dependencies and explicit Nx task dependencies; the declaration builds
include the generated stand-ins. The suite generates and emits in every
order, checks that stand-ins and real contracts emit identical declarations
and asserts the leak boundary of a type imported from a used module.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
a7e7465150 fix(router-devtools-core): list module routes without the module root
The mount path row already shows a module's root; its route list no longer
repeats it. The panel's matches are memoized, and the tests cover a module
installed several times.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
3767ebee6a feat(eslint-plugin-router): report imports from used route modules
A route module links into the modules it uses through generated namespaces;
its declaration build compiles against stand-ins for their contracts, so a
type imported from a used module would be emitted with the stand-in's types.
The rule now reports every import from a module listed in `uses` (values,
types, re-exports and dynamic imports) and covers `useLinkProps`,
`useBlocker`, `notFound` and `createMiddleware`. Package declarations are
read once per package.json and revalidated by mtime.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
ec679c132d feat(router-generator): link route modules in both directions
`uses` is a contract relation: generation reads only the used package's
package.json (dependencies, devDependencies or peerDependencies), never its
manifest, so two modules can use each other and a module can use the module
that includes it. The declaration build compiles against generated stand-ins
for the used contracts (`.tanstack/route-types-stubs.d.ts`); the contract
(`routeContract.gen.ts`) now declares the module's register and router and
reaches only the module's own files, the framework and the contracts of
included modules. Include cycles are rejected with a diagnostic.

Generated files are kept in sync: files that are not generated anymore are
removed, also when a package stops being a route module, and a generated
file deleted or edited in watch mode is regenerated. Every generated file is
written atomically through the generator's file system. Generated namespaces
and contracts import only what they use, so `noUnusedLocals` passes on them.
Diagnostics name a single named installation instead of "several times".

The route-module context no longer carries derivable state (installations,
manifests, watch-file lists); mount placement is resolved once per build.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
b6b0d0a080 fix(router-generator): name the namespace file callback type
Its declaration referenced the namespace type through import('.'),
which Node16 ESM resolution rejects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
f15819fdf1 test(router-generator): read generated files by their absolute path
Joining an absolute Windows path onto '/' produced 'D:\C:\...'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
c460e6e0d5 chore(changeset): mention the namespace file layout option
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
195f21820d perf(route-modules): no Link or useNavigate cost without route modules
`Link` and `useNavigate` added the nearest route to every navigation,
read the match context and listed the route-module options, although
only the route-module translation reads them. They now do so only when
route-module code installed that translation, which it does before an
application renders, and the framework links learn the internal scope
options (`_module`, `_fromRoute`) from route-module code. Without route
modules the branches fold away, as do the not-found boundary's module
resolution and `buildLocation`'s options alias.

With Vite, react-router.minimal, react-start.minimal and the minimal
Solid scenarios now match main byte for byte. Rsbuild does not fold the
never-assigned hooks and keeps the module branches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
2269acc46d feat(router-generator): configurable route-module namespace files
`routeScopeNamespaceFiles` places the generated namespace files of a
route scope: 'indexed' (default, `routeScope.gen.namespace<N>.ts`),
'named' (`routeScope.gen.<namespace>.ts`), 'folder'
(`routeScope.gen/<namespace>.ts`) or a function returning the path
relative to the route tree's directory.

Namespace files import the route tree from their own location. Paths
must stay inside the generated directory and outside the routes
directory, and differ in more than letter case. Changing the layout
removes the files of the previous one, which the previous scope file
lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
cdf03e1cc9 test(bundle-size): measure apps with a mounted route module
Add `react-router.route-modules` and `react-start.route-modules`: the
minimal application with a small workspace route module mounted at
`/feature`, linked through its namespace and reading the router through
the module's scope. Each scenario generates the module before building.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
3406eb1e09 perf(route-modules): ship route-module behavior only with route modules
Applications without route modules still bundled the module branches of
the core and the framework route APIs: `buildLocation`'s module-local
translation, `getRouteNavigationScope` in every route's `redirect`,
`useNavigate` and `Link`, and the module-root id in route init.

- router-core: route-module code installs these as hooks
  (`route-module-hooks.ts`) from `mountRouteModule`, module roots and
  scoped options. They are never assigned without route modules, so
  bundlers drop every branch that reads them. The per-module check of
  the translation reports a module that is used but not installed.
- useNavigate passes its route-module defaults through without naming
  them; Link no longer lists the constant `_fromRoute` as a dependency.
- router-generator: scopes export the framework's own APIs where the
  scope binds nothing (`useMatches`, `useLocation`, `useRouterState`,
  `useBlocker`, ... and the id-based APIs outside one installation of a
  module installed several times) instead of calling a binder.

react-router.minimal: -87 B gzip, react-start.minimal: -122 B gzip
against the previous head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
e365d5ebbd fix(ci): unify Vite's sass peer instead of deduping the lockfile
The workspace-wide `pnpm dedupe` also upgraded unrelated tooling: Rsbuild
and Rspack for the bundle-size benchmark, and @typescript-eslint/utils
apart from its rule tester, which broke the eslint plugin's build.
Restore the previous resolution and give Vite's optional sass peer one
version from the workspace root, the one the Start plugins already used,
so every application shares their Vite instance.

Also look up mounted module route files by their forward-slash keys in
the remaining generator tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:24 +01:00
Manuel Schiller
efa5e5165e test(route-modules): run Start build tests downstream and fix CI setup
- Move the route-module bundler tests out of start-plugin-core into
  react-start, solid-start and vue-start, which test their own public
  Vite and Rsbuild plugins against their build. Upstream packages no
  longer need downstream builds.
- Move the Start namespace alias test from router-generator into the
  React Start route-modules fixture, which publishes real Start modules.
- Generate into each temporary workspace's own tmpDir: renaming from the
  cwd-relative default failed across devices on CI.
- React Router route-modules fixture: declare that the web build needs
  the modules' generate and emit-types tasks, and depend on the web
  package so its tools are built before the fixture's tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:12 +01:00
Manuel Schiller
aaa64fc21d fix(route-modules): keep HMR updates and Windows lookups for mounted modules
- start-plugin-core: the client route tree plugin sent a full reload on
  every route tree change, so adding or removing a route option such as
  `loader` or `beforeLoad` discarded client state instead of hot updating.
  Reload only when the routes the client keeps change: the application's
  pruned tree, the provider tree mapping or a provider's client tree.
- router-generator: key mounted module route files with forward slashes
  like the package's own route files. The router plugin looks them up by
  normalized module id, so on Windows module routes missed HMR and code
  splitting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:00 +01:00
Manuel Schiller
d4ff4c76ae fix(e2e): serve the Start route-modules dev app from one Vite copy
The route-modules importers resolved Vite with a different optional
sass peer than the Start plugins, so the dev server got a second Vite
instance, failed the RunnableDevEnvironment check and never installed
the SSR middleware: every page answered "Cannot GET". Dedupe the
lockfile so all importers share one Vite, keeping prettier and
tinyglobby at their previous versions.

Also import the route-modules config with its extension, which Vite's
native config loader requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:33:00 +01:00
Manuel Schiller
2cb70db815 test(route-modules): tidy the settings profile fixture pages
Group the profile page's API probes into labeled Match, Links and
Navigation sections and give them spacing. Point the framework Link
probes and the React deferred members link at orgs the fixtures
actually use instead of arbitrary ids, and style the installation
switcher in the React fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:31:50 +01:00
Manuel Schiller
762f949606 feat: experimental route modules for file-based routing
Route modules are workspace packages that own a subtree of file-based routes and are mounted into applications or other modules. A package declares `tanstack.router.module` in its package.json. The generator gives it qualified route ids (`<pkg>:<path>`), a generated route scope (`routeScope.gen.ts` plus one namespace file per included or used module), a public contract (`routeContract.gen.ts`, exported as `./route-types` after the package's own declaration build), a runtime entry (`routeModule.gen.ts`, exported as `./route-module`) and a topology manifest (`.tanstack/route-module.json`). Includers mount modules with the `routeModules` option: `includes` chooses the host route and mount path, optionally under path params, `uses` references modules mounted elsewhere, and an application installs a module several times by including it once per installation named with `as`, each with its own namespace and route ids (`<pkg>#<as>:<path>`). Matches of module routes carry `localRouteId`, and the generated `isScopedMatch` guard narrows whole-router matches by module id prefix.

Runtime: the generated host tree mounts module roots with the internal `mountRouteModule`; module-local ids, destinations, redirects and not-found errors resolve to the installation of the route that uses them; `HostedRouter` types the links of code that mounts modules under path params. Type composition is contract-based through `./route-types`; the framework packages augment `@tanstack/router-core/extensions` and export `RouteCore`.

Start: modules get `createServerFn`, `createMiddleware` and `createStartModule` in their scope, declare required context by augmenting `StartModuleRequirements`, and contribute fragments that applications install with `createStart(() => ({ extends: startModules }))`; `startModules.gen.ts` type-checks installation and requirements. The Start plugin lists module routes in the routes manifest, selects the providers' client tree views, discovers prerenderable module pages and extends import protection to module packages.

Build and tooling: the host bundler compiles, code-splits and hot-updates module routes, including every installation; `tsr generate` and `tsr watch` are the only commands and packages own their declaration builds; the devtools show modules; the `route-module-imports` ESLint rule enforces scope imports. Fixtures cover React, Solid, Vue and Start with Vite and Rsbuild, and a large example measures builds.
2026-11-11 14:31:50 +01:00
543 changed files with 38204 additions and 3435 deletions

Some files were not shown because too many files have changed in this diff Show more