Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Feb 2, 2026

Summary by CodeRabbit

  • New Features

    • Routes now include a routeId in context options and beforeLoad/context callbacks for all route configurations
    • Added exported rootRouteId constant to identify the root route
  • Tests

    • Added extensive tests verifying routeId propagation across root, nested, dynamic, layout, redirect, navigation, reload, and beforeLoad/context scenarios

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

Threads a routeId identifier through route context and beforeLoad option types by adding a TRouteId generic and populating routeId: route.id in context objects; updates tests to assert presence for root, nested, dynamic, and layout routes and exports rootRouteId for tests.

Changes

Cohort / File(s) Summary
Core Type/Interface Updates
packages/router-core/src/route.ts, packages/router-core/src/load-matches.ts
Introduce TRouteId generics across route/context/beforeLoad types; add routeId to the beforeLoad context (sourced from route.id).
Router Context Building
packages/router-core/src/router.ts, packages/router-core/src/ssr/ssr-client.ts
Extend RouteContextOptions to accept an extra generic and include routeId: route.id in the context objects passed to route context functions (alongside location, navigate, buildLocation, etc.).
Public API / Exports
packages/router-core/... (public export surface)
Add/export rootRouteId for identifying the root route in tests.
Server/Integration Types
packages/start-client-core/src/serverRoute.ts
Add TRouteId generic to BeforeLoadContextOptions usage in server-side route typings.
Type Assertion Tests (React, Solid, Vue)
packages/react-router/tests/route.test-d.tsx, packages/solid-router/tests/route.test-d.tsx, packages/vue-router/tests/route.test-d.tsx
Add routeId literal-typed fields to hook/context option type assertions for root, child, nested, dynamic, and layout routes.
Behavioral Tests
packages/react-router/tests/routeContext.test.tsx, packages/router-core/tests/load.test.ts
Add tests validating routeId propagation through context and beforeLoad across various routing scenarios and reference rootRouteId.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • chorobin
  • nlynzaad
  • beaussan

Poem

🐰 I hopped along the routing line,
Left little IDs where pathways twine,
From root to leaf, each match I thread,
A tiny token on each bed,
Now contexts know where I did dine. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: pass routeId into context/beforeLoad' accurately describes the main change: adding the routeId parameter to context and beforeLoad callbacks across multiple router packages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/routeId-context

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@Sheraff Sheraff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-router/tests/routeContext.test.tsx (1)

13-23: ⚠️ Potential issue | 🟡 Minor

Use rootRouteId (or drop the import) to satisfy lint.

ESLint reports the import as unused. The hardcoded '__root__' string at line 727 should be replaced with rootRouteId to fix this.

Suggested fix
-    expect(mock).toHaveBeenCalledWith('__root__')
+    expect(mock).toHaveBeenCalledWith(rootRouteId)

Also applies to: 710-728

@nx-cloud
Copy link

nx-cloud bot commented Feb 2, 2026

View your CI Pipeline Execution ↗ for commit 4a833e9

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 10m 50s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 42s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-02 23:58:49 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6579

@tanstack/eslint-plugin-router

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

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6579

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6579

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6579

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6579

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6579

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6579

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6579

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6579

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6579

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6579

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6579

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6579

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6579

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6579

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6579

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6579

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6579

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6579

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6579

commit: 4a833e9

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/router-core/src/route.ts (1)

860-874: ⚠️ Potential issue | 🟡 Minor

RouteContextFn generic order misaligns with RouteContextOptions signature.

RouteContextFn passes TSearchValidator and omits TLoaderDeps when constructing RouteContextOptions, causing parameter positions to shift. The correct order should be TParentRoute, TParams, TRouterContext, TLoaderDeps, TRouteId to match the RouteContextOptions interface definition.

🔧 Suggested fix
 export type RouteContextFn<
   in out TParentRoute extends AnyRoute,
   in out TSearchValidator,
   in out TParams,
   in out TRouterContext,
+  in out TLoaderDeps,
   in out TRouteId,
 > = (
   ctx: RouteContextOptions<
     TParentRoute,
-    TSearchValidator,
     TParams,
     TRouterContext,
+    TLoaderDeps,
     TRouteId
   >,
 ) => any

@schiller-manuel schiller-manuel merged commit a894baa into main Feb 2, 2026
6 checks passed
@schiller-manuel schiller-manuel deleted the feat/routeId-context branch February 2, 2026 23:59
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.

3 participants