Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Jan 17, 2026

fixes #6082

Summary by CodeRabbit

  • Performance Improvements
    • Optimized route navigation to reduce store update frequency across React Router, Solid Router, and Vue Router implementations, resulting in fewer state updates during navigation transitions.
    • Improved context data handling to be applied more efficiently during route matching and loader execution.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

This PR refactors where route match context is built and attached during navigation. Instead of using deferred commitContext calls, context is now constructed directly within state updates—during loader execution and redirect/not-found handling—resulting in fewer store updates across the routing system.

Changes

Cohort / File(s) Summary
Core context attachment refactoring
packages/router-core/src/load-matches.ts
Context is now built inline at state update points (success, error, redirect/notFound) via buildMatchContext(inner, index) rather than through separate commitContext calls. Removes deferred context commits from loadRouteMatch finalization blocks.
Test expectation updates - React Router
packages/react-router/tests/store-updates-during-navigation.test.tsx
Adjusted expected store update counts downward across multiple navigation tests to reflect consolidated context building (e.g., 11→10, 5→4, 10→9, 8→6, 19→16).
Test expectation updates - Solid Router
packages/solid-router/tests/store-updates-during-navigation.test.tsx
Reduced expected update counts in navigation tests (e.g., 11→10, 7→6, 10→8, 19→16, 9→7, 5→3) to align with consolidated context handling.
Test expectation updates - Vue Router
packages/vue-router/tests/store-updates-during-navigation.test.tsx
Adjusted expected update counts downward across tests (33→27, 13→10, 31→25, 47→38, 24→18, 22→16, 18→12, 6→3) to reflect the reduced number of store updates from consolidated context building.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

package: router-core, package: react-router, package: solid-router, package: vue-router

Suggested reviewers

  • nlynzaad

Poem

🐰 Context now blooms where updates flow,
No more deferred commits steal the show,
Consolidated paths, a cleaner way—
Fewer ripples in the store each day! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: committing context together with status to avoid a race condition, which directly addresses the issue of undefined context values.
Linked Issues check ✅ Passed The PR addresses issue #6082 by fixing how context is committed with status updates in load-matches.ts, which resolves the race condition causing useRouteContext() to return undefined.
Out of Scope Changes check ✅ Passed Test file updates in React Router, Solid Router, and Vue Router reflecting lower update counts are consistent with the core fix reducing unnecessary context commits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

@nx-cloud
Copy link

nx-cloud bot commented Jan 17, 2026

View your CI Pipeline Execution ↗ for commit 85c6cfa

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

☁️ Nx Cloud last updated this comment at 2026-01-17 23:57:47 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 17, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 85c6cfa

@schiller-manuel schiller-manuel merged commit abb8216 into main Jan 18, 2026
6 checks passed
@schiller-manuel schiller-manuel deleted the fix-commit-context branch January 18, 2026 00:01
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.

getRouteApi().useRouteContext() returns undefined for beforeLoad context values in v1.140.1+

2 participants