Skip to content

refactor(router): hide undocumented internals from the published types - #9035

Draft
schiller-manuel wants to merge 8 commits into
chore/api-extractor-reportsfrom
refactor/hide-router-internals
Draft

schiller-manuel wants to merge 8 commits into
chore/api-extractor-reportsfrom
refactor/hide-router-internals

Conversation

@schiller-manuel

Copy link
Copy Markdown
Collaborator

🎯 Changes

Stacked on #9034.

A name that docs/ does not document is internal. This tags those names @internal in router-core, history and the three router bindings, so they leave the declarations users install and stay typed for workspace packages (through dist-ts). Runtime is unchanged: emitted .js/.cjs is byte-identical, apart from dist/source/index.jsx in solid-router and vue-router, where split export statements show up as written (same names, same modules).

The diff of packages/*/api/*.api.md is the list of what left the public surface; the changeset lists the names by group.

  • Members: 49 on the router, 8 on matches, 7 on routes, 12 on the history, 11 option fields.
  • Exports: 55 value exports of router-core's root entry, most of its subpath exports, createHistory, parseHref and normalizeProtocolRelative in history, and 19 to 22 re-exports per binding. Entry files now keep hidden names in their own tagged export { … } from statement.
  • Exported types that no public declaration reaches and the docs do not name (listed below).
  • // @internal is used where the bundler keeps JSDoc on top-level functions, constants and class methods, so the JavaScript stays identical. TypeScript strips both forms.
  • Docs: remove commitLocation and the routesByPath / routesById samples, add match.fullPath, document history.back / forward / go.
  • e2e and benchmarks: replace deepEqual and route.options uses, move the hydration benchmarks to router.state, opt the dev-ssr-styles tests and five client-nav benchmarks into the internal types with a compile dependency. The *-full bundle-size scenarios drop Asset, Match, Matches, RouterContextProvider and useTags, so they measure less (−57 to −94 B gzip); every other scenario is unchanged.

Kept public for now:

  • Names the Start packages' published declarations still re-export, until the next pull request: RawStream, and on /ssr/client and /ssr/server hydrate, json, mergeHeaders, defaultSerovalDeserializerPlugins, attachRouterServerSsrUtils, transformReadableStreamWithRouter, transformPipeableStreamWithRouter.
  • Undocumented, kept by ruling: router.serverSsr, router.routesById, createSerializationAdapter, isMatch, SearchParamError, PathParamError, serializationAdapters, ssr.nonce, Body / Html (vue), ScrollRestoration.

Open questions, kept public until decided:

  • LazyRoute: two router-monorepo-simple-lazy examples use it as a type.
  • Route.Link, RouteApi.Link, RouteApi.notFound: used in e2e projects, not documented.
  • trailingSlashOptions, defaultSerializeError, DEV_STYLES_ATTR are hidden from the entry but public types still use them through typeof.
Exported types hidden because nothing public references them

AnyRouteWithContext, AnyRouterWithContext, AnySearchValidator, AnyStandardSchemaValidateInput, AnyValidatorFn, CommitLocationFn, CommitLocationOptions, ControllablePromise, ControlledPromise, CreateLazyFileRoute, DefaultSearchValidator, EmitFn, ErrorRouteProps, GetMatchRoutesFn, IsAny, IsUnion, LoadRouteChunkFn, MatchLocation, MergeAll, MergeAllObjects, MetaDescriptor, ParseLocationFn, PickRequired, PreloadableObj, ResolvedRedirect, ResolveSearchSchema, ResolveSearchSchemaFn, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, RouteContextFn, RouteLinkEntry, RoutePathOptionsIntersection, RouterConfig, RouterConfigOptions, RouterConfigTypes, AnyRouterConfig, RouterListener, RouterManagedInlineCssTag, RouterStores, SearchValidator, StartTransitionFn, StringLiteral, Timeout, ValidateId, ValidateNavigateOptionsArray, ValidateParams, ValidateRedirectOptionsArray, ValidateSearch, ValidateToPath, ValidateUseParamsResult, ValidateUseSearchResult, WithoutEmpty

Bindings only: ValidateUseSearchOptions, ValidateUseParamsOptions, InferStructuralSharing (react), VueNode (vue). history: NavigationBlocker.

Also hidden beyond the agreed lists (undocumented, unused outside packages/): the match fields the bindings add (meta, links, scripts, styles, headScripts), HistoryState.__hashScrollIntoViewOptions, FileRoute.silent, RouterStores._linkScopes.

Validated locally for packages/* without the Nx cache: build, compile, test:types, test:unit, test:eslint, test:build (231 tasks), and tsc over all 419 example, e2e and benchmark tsconfigs with no new failures. Not run: the Playwright e2e suites. Draft because it inherits the red test:build of #9032 until TanStack/config#443 is released.

Written with AI assistance (Claude Code).

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

🤖 Generated with Claude Code

schiller-manuel and others added 8 commits November 30, 2026 03:29
`LoadTransaction` reads `AnyRouter['_handoff']` and react-router's
`settleOwner` takes `AnyRouter['_rendered']`. Both members become
internal in the following commits, and these declarations would then
reference a member the published declarations no longer have. Tag them
`@internal`, together with `PendingSession` and `commitMatches`, which
use `LoadTransaction`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ublished types

Tag with `@internal` the router, match, route and history members, the
option fields and the entry-point exports that the docs do not
document. They stay in the internal declarations that workspace
packages read, and the emitted JavaScript is unchanged.

Export statements of the entry files are split so that the hidden
names have their own tagged statement; the set of runtime exports per
entry is the same. Declarations whose leading JSDoc the bundler keeps in
the output (top-level functions and constants, class methods) use a
`// @internal` line comment instead, which the bundler drops.

`RawStream`, `hydrate`, `json`, `mergeHeaders`,
`defaultSerovalDeserializerPlugins`, `attachRouterServerSsrUtils`,
`transformReadableStreamWithRouter` and
`transformPipeableStreamWithRouter` stay public for now, because the
published declarations of the Start packages re-export them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ernals from the published types

Tag the bindings' re-exports of hidden core and history names, their own
undocumented exports (`Matches`, `Match`, `Asset`, `useTags`,
`RouterContextProvider`, `FileRouteLoader`, and `useLayoutEffect` and
`reactUse` in react-router), and undocumented members they add: the
`meta`, `links`, `scripts`, `styles` and `headScripts` match fields,
`HistoryState.__hashScrollIntoViewOptions`, `FileRoute.silent` and
react-router's `RouterStores._linkScopes`.

`LazyRoute` stays public: the monorepo examples use it as a type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once the internals are hidden, these exported types are no longer
reached from any public export of router-core, history or the bindings,
and the docs do not name them. Types that another package's published
declarations import (`InferSelected`, `InferShouldThrow`,
`InferStrict`, `RouteLoaderEntry`, `CreateFileRoute`,
`ResolveValidatorInput`, `ResolveValidatorInputFn`,
`UnionToIntersection`, `OnRawStreamCallback`) stay public.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ation

Remove the `commitLocation` section and its mention in the SSR guide,
pass route objects to `loadRouteChunk` in the preloading samples in
place of `router.routesByPath`, and remove the `router.routesById`
snippets from the debugging guide. Add `fullPath` to the `RouteMatch`
type and document `history.back`, `history.forward` and
`history.go`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The server-functions e2e routes compare results with a local helper in
  place of `deepEqual`.
- The vitest-app e2e tests read `route.options` through a typed helper,
  since the project also runs as an installed copy outside the repository.
- The hydration benchmarks read `router.state` in place of
  `router.stores`.
- The dev-ssr-styles e2e tests (`DEV_STYLES_ATTR`) and the client-nav
  link-performance, history, rewrites and hydration benchmarks
  (`history.location`, `history.length`, `@tanstack/router-core/isServer`
  and the `isServer` router option) opt into the internal declarations by
  extending `packages/tsconfig.paths.json`, and their type checks now
  depend on `compile`. The dev-ssr-styles projects keep their own
  `paths`, so the opt-in sits in a tsconfig for the tests only.
- The `*-full` bundle-size scenarios drop the hidden exports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 924f4e2

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

This PR includes changesets to release 24 packages
Name Type
@tanstack/router-core Patch
@tanstack/history Patch
@tanstack/react-router Patch
@tanstack/solid-router Patch
@tanstack/vue-router Patch
@tanstack/react-start-client Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start-server Patch
@tanstack/router-generator Patch
@tanstack/router-plugin Patch
@tanstack/solid-start-client Patch
@tanstack/solid-start-server Patch
@tanstack/start-client-core Patch
@tanstack/start-plugin-core Patch
@tanstack/start-server-core Patch
@tanstack/start-storage-context Patch
@tanstack/vue-start-client Patch
@tanstack/vue-start-server Patch
@tanstack/react-start Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch
@tanstack/router-cli Patch
@tanstack/router-vite-plugin Patch
@tanstack/start-static-server-functions 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

@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nx-cloud

nx-cloud Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 924f4e2

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 9m 2s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 7s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-30 02:42:12 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

12 package(s) bumped directly, 17 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/history 1.162.5 → 1.162.6 Changeset
@tanstack/react-router 1.170.46 → 1.170.47 Changeset
@tanstack/react-router-devtools 1.167.4 → 1.167.5 Changeset
@tanstack/react-start-rsc 0.1.69 → 0.1.70 Changeset
@tanstack/router-core 1.171.39 → 1.171.40 Changeset
@tanstack/router-devtools-core 1.168.4 → 1.168.5 Changeset
@tanstack/router-plugin 1.170.0 → 1.170.1 Changeset
@tanstack/solid-router 1.170.43 → 1.170.44 Changeset
@tanstack/solid-router-devtools 1.167.4 → 1.167.5 Changeset
@tanstack/start-plugin-core 1.173.0 → 1.173.1 Changeset
@tanstack/vue-router 1.170.42 → 1.170.43 Changeset
@tanstack/vue-router-devtools 1.167.4 → 1.167.5 Changeset
@tanstack/react-start 1.170.0 → 1.170.1 Dependent
@tanstack/react-start-client 1.168.45 → 1.168.46 Dependent
@tanstack/react-start-server 1.167.52 → 1.167.53 Dependent
@tanstack/router-cli 1.168.1 → 1.168.2 Dependent
@tanstack/router-devtools 1.167.4 → 1.167.5 Dependent
@tanstack/router-generator 1.169.0 → 1.169.1 Dependent
@tanstack/router-vite-plugin 1.167.50 → 1.167.51 Dependent
@tanstack/solid-start 1.170.0 → 1.170.1 Dependent
@tanstack/solid-start-client 1.168.42 → 1.168.43 Dependent
@tanstack/solid-start-server 1.167.50 → 1.167.51 Dependent
@tanstack/start-client-core 1.170.39 → 1.170.40 Dependent
@tanstack/start-server-core 1.169.45 → 1.169.46 Dependent
@tanstack/start-static-server-functions 1.167.44 → 1.167.45 Dependent
@tanstack/start-storage-context 1.167.41 → 1.167.42 Dependent
@tanstack/vue-start 1.170.0 → 1.170.1 Dependent
@tanstack/vue-start-client 1.167.45 → 1.167.46 Dependent
@tanstack/vue-start-server 1.167.50 → 1.167.51 Dependent

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: af236509f654
  • Measured at: 2026-11-30T02:34:41.110Z
  • Baseline source: history:a47dc36d0310
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes compared with the baseline:

Scenario Current (gzip) Initial (gzip) Raw Brotli Trend
react-router.minimal 84.0 KiB
-15 B
83.9 KiB
-14 B
261.5 KiB
-25 B
73.3 KiB
-39 B
▁▆▆▆▆▆▆▆▆██▄
react-router.full 87.5 KiB
-73 B
87.4 KiB
-72 B
273.2 KiB
-219 B
76.5 KiB
+84 B
▅▇▇▇▇▇▇▇▇██▁
solid-router.minimal 33.4 KiB
-13 B
33.2 KiB
-12 B
95.3 KiB
-25 B
30.2 KiB
-43 B
▁██████████▆
solid-router.full 38.2 KiB
-83 B
38.1 KiB
-82 B
109.9 KiB
-213 B
34.5 KiB
-99 B
▆██████████▁
vue-router.minimal 49.5 KiB
-12 B
49.3 KiB
-11 B
136.5 KiB
-50 B
44.8 KiB
-8 B
▁██████████▆
vue-router.full 55.0 KiB
-72 B
54.9 KiB
-71 B
154.4 KiB
-250 B
49.6 KiB
-51 B
▃██████████▁
react-start.minimal 96.8 KiB
-10 B
96.7 KiB
-11 B
302.4 KiB
-25 B
84.1 KiB
-18 B
▁▅▅▅▅▅▅▅▅██▄
react-start.query-integration 104.2 KiB
-14 B
104.1 KiB
-12 B
329.0 KiB
-25 B
90.6 KiB
+53 B
▁▅▅▅▅▅▅▅▅██▄
react-start.deferred-hydration 97.5 KiB
-12 B
96.7 KiB
-11 B
303.8 KiB
-25 B
84.7 KiB
-130 B
▁▆▆▆▆▆▆▆▆██▆
react-start.full 99.8 KiB
-76 B
99.7 KiB
-73 B
311.5 KiB
-218 B
86.7 KiB
-89 B
▆▇▇▇▇▇▇▇▇██▁
react-start.rsbuild.minimal 96.7 KiB
-13 B
96.5 KiB
-13 B
298.3 KiB
-25 B
83.5 KiB
-26 B
▇█████████▅▁
react-start.rsbuild.minimal-iife 97.1 KiB
-14 B
96.9 KiB
-14 B
299.2 KiB
-25 B
83.7 KiB
-103 B
▆█████████▅▁
react-start.rsbuild.full 99.9 KiB
-87 B
99.7 KiB
-87 B
307.7 KiB
-229 B
86.0 KiB
-126 B
██████████▇▁
solid-start.minimal 46.2 KiB
-11 B
46.1 KiB
-12 B
135.1 KiB
-25 B
41.1 KiB
-106 B
▁██████████▇
solid-start.deferred-hydration 49.2 KiB
-10 B
46.1 KiB
-12 B
142.4 KiB
-25 B
43.9 KiB
-35 B
▁██████████▇
solid-start.full 51.1 KiB
-113 B
51.0 KiB
-110 B
149.8 KiB
-322 B
45.3 KiB
-125 B
▄██████████▁
vue-start.minimal 65.4 KiB
-14 B
65.3 KiB
-13 B
185.7 KiB
-50 B
58.3 KiB
-36 B
▁██████████▆
vue-start.full 69.1 KiB
-84 B
69.0 KiB
-84 B
197.4 KiB
-245 B
61.5 KiB
-151 B
▃██████████▁

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@9035

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@9035

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@9035

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@9035

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@9035

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@9035

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@9035

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@9035

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@9035

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@9035

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@9035

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@9035

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@9035

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@9035

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@9035

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@9035

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@9035

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@9035

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@9035

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@9035

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@9035

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@9035

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@9035

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@9035

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@9035

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@9035

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@9035

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@9035

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@9035

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@9035

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@9035

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@9035

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@9035

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@9035

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@9035

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@9035

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@9035

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@9035

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@9035

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@9035

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@9035

commit: 924f4e2

@codspeed

codspeed Bot commented Nov 30, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 6.14%

Warning

TanStack has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 13, 2026 to keep using CodSpeed.

1 warning, 1 note

⚠️ 50 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 2 benchmarks have no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

❌ 2 regressed benchmarks
✅ 198 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory mem client loader-data-retention (solid) 95.1 KB 102.4 KB -7.11%
❌ Memory mem client unique-location-churn (react) 73.6 KB 77.6 KB -5.16%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing refactor/hide-router-internals (924f4e2) with chore/api-extractor-reports (deb48b8)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant