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

Compare commits

...

14 commits

Author SHA1 Message Date
Manuel Schiller
3325eb7451 feat(route-modules): install route-module behavior with createRouteModuleRouter
Applications that mount route modules create their router with
`createRouteModuleRouter`, a named export of React, Solid and Vue Router
with the options and return type of `createRouter`. It is the one place
that installs the route-module behavior of the core and of the framework
links, before the router is created.

- The core keeps that behavior in one never-assigned `routeModules`
  binding, which bundlers fold away in applications without route
  modules.
- Module code (`mountRouteModule`, generated scopes, module roots and
  scoped binders) no longer installs anything, so no install side effect
  hides behind `/* @__PURE__ */` calls.
- Nothing reads the behavior at import: the template root of a module
  installed several times takes its `<pkg>:` id itself.
- In development, `createRouter` throws when its route tree contains a
  mounted module or when it receives options from generated module APIs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 18:53:23 +01:00
Manuel Schiller
5a87486046 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-02 08:51:24 +01:00
Manuel Schiller
07aed5fe99 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-02 08:34:19 +01:00
Manuel Schiller
a2ac4775ed chore(changeset): mention the namespace file layout option
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 08:27:37 +01:00
Manuel Schiller
7593e793a1 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-02 08:27:21 +01:00
Manuel Schiller
899c7c9128 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-02 08:27:21 +01:00
Manuel Schiller
1e2e680573 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-02 02:25:51 +01:00
Manuel Schiller
b5de7587c0 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-02 02:25:51 +01:00
Manuel Schiller
51d00d1830 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-02 01:49:03 +01:00
Manuel Schiller
5960ab43ab 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-02 01:24:54 +01:00
Manuel Schiller
fc208125cd 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-02 01:24:49 +01:00
Manuel Schiller
6ea1ab6659 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-02 00:34:59 +01:00
Manuel Schiller
b2ad239b6b 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-02 00:21:37 +01:00
Manuel Schiller
99df5ae424 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-02 00:02:35 +01:00
527 changed files with 35531 additions and 1545 deletions

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