Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(router): restrict useRouteContext in pendingComponent to parent routes - #9016

Open
Sheraff wants to merge 2 commits into
mainfrom
t3/explain-non-route-context
Open

Sheraff wants to merge 2 commits into
mainfrom
t3/explain-non-route-context

Conversation

@Sheraff

@Sheraff Sheraff commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

🎯 Changes

In non-production builds, throw when useRouteContext is called inside a route's pendingComponent (or router defaultPendingComponent) for self, descendants, or { strict: false }. Only strict ancestor route contexts are allowed. Everything is gated behind process.env.NODE_ENV !== 'production' and compiles to 0 bytes in production.

  • @tanstack/router-core: add _assertPendingRouteContextAccess(pendingRoute, from) walking pendingRoute.parentRoute.
  • @tanstack/{react,solid,vue}-router: attach the pending route to the dev-only nonRouteComponentContext and validate in useRouteContext (including Vue reactive fallback transitions).
  • Tests: add pending-route-context-access.test.tsx across React, Solid, and Vue; update existing tests (issue-7986-retained-pending, issue-8115-context, e2e/react-router/issue-4759) that read self.useRouteContext() inside a pendingComponent to read from the parent route instead.

AI-assisted PR (authored with AI assistance and verified locally with unit, type, eslint, and bundle-size checks).

✅ 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).

Summary by CodeRabbit

  • Bug Fixes
    • Pending components in React, Solid, and Vue routers can access context from parent routes. Attempts to access their own or descendant route context now produce a clear error in development.
    • Corrected context handling for route-level and default pending components during loading and navigation.
    • These development-time checks are omitted from production builds.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9cbbe25

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

This PR includes changesets to release 23 packages
Name Type
@tanstack/router-core 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

@nx-cloud

nx-cloud Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 9cbbe25

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 8m 37s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 9s 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-27 20:26:35 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

4 package(s) bumped directly, 19 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.46 → 1.170.47 Changeset
@tanstack/router-core 1.171.39 → 1.171.40 Changeset
@tanstack/solid-router 1.170.43 → 1.170.44 Changeset
@tanstack/vue-router 1.170.42 → 1.170.43 Changeset
@tanstack/react-start 1.169.7 → 1.169.8 Dependent
@tanstack/react-start-client 1.168.45 → 1.168.46 Dependent
@tanstack/react-start-rsc 0.1.68 → 0.1.69 Dependent
@tanstack/react-start-server 1.167.52 → 1.167.53 Dependent
@tanstack/router-cli 1.168.0 → 1.168.1 Dependent
@tanstack/router-generator 1.168.0 → 1.168.1 Dependent
@tanstack/router-plugin 1.169.0 → 1.169.1 Dependent
@tanstack/router-vite-plugin 1.167.49 → 1.167.50 Dependent
@tanstack/solid-start 1.169.7 → 1.169.8 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-plugin-core 1.172.0 → 1.172.1 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.169.7 → 1.169.8 Dependent
@tanstack/vue-start-client 1.167.45 → 1.167.46 Dependent
@tanstack/vue-start-server 1.167.50 → 1.167.51 Dependent

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

In development, useRouteContext allows pending components to access ancestor route contexts and rejects access to their own or descendant contexts. React, Solid, and Vue pass pending-route identity through their rendering contexts and add coverage for these access rules.

Changes: Pending Route Context Access

Layer / File(s) Summary
Shared access rule
packages/router-core/src/useRouteContext.ts, packages/router-core/src/index.ts
Adds and exports _assertPendingRouteContextAccess. It allows ancestor route IDs and throws for other requested route IDs.
React Router integration and coverage
packages/react-router/src/*, packages/react-router/tests/*pending-route-context-access.test.tsx, packages/react-router/tests/issue-7986-retained-pending.test.tsx, packages/react-router/tests/issue-8115-context.test.tsx, e2e/react-router/issue-4759/src/main.tsx, .changeset/restrict-pending-route-context.md
React pending-render contexts carry route identity, and development-mode useRouteContext applies the shared assertion. Tests cover allowed and rejected access. Existing examples and tests read parent contexts.
Solid Router integration and coverage
packages/solid-router/src/*, packages/solid-router/tests/*pending-route-context-access.test.tsx, packages/solid-router/tests/issue-7986-retained-pending.test.tsx, packages/solid-router/tests/issue-8115-context.test.tsx
Solid pending-render contexts carry route identity, and development-mode useRouteContext applies the shared assertion. Tests cover allowed and rejected access. Existing tests read parent contexts.
Vue Router integration and coverage
packages/vue-router/src/*, packages/vue-router/tests/*pending-route-context-access.test.tsx, packages/vue-router/tests/issue-7986-retained-pending.test.tsx, packages/vue-router/tests/issue-8115-context.test.tsx
Vue pending-render contexts carry route identity, and development-mode useRouteContext applies the shared assertion. Tests cover allowed and rejected access, including a component used for both error and pending states.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant PendingComponent
  participant useRouteContext
  participant nonRouteComponentContext
  participant _assertPendingRouteContextAccess
  PendingComponent->>useRouteContext: Request route context
  useRouteContext->>nonRouteComponentContext: Read pending route
  useRouteContext->>_assertPendingRouteContextAccess: Check requested route ID
  _assertPendingRouteContextAccess-->>useRouteContext: Allow ancestor access or throw
  useRouteContext-->>PendingComponent: Return context when allowed
Loading

Possibly related issues

  • Issue 9009 — The issue describes a pending component accessing its own route context. This change adds a development-mode error for that access and permits ancestor contexts.

Suggested reviewers: schiller-manuel, brenelz

Merge Risk: Minimal · up to 9cbbe

This change adds a development-only error when a pending component reads its own or a descendant route's context. Production behavior is unchanged, and no merge-blocking risk is identified from the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: restricting useRouteContext inside pendingComponent to parent routes. The changeset adds an assertion in router-core and wires the pending route into the React, Solid,…
Description check Passed The description follows the template. It has the Changes section, which explains the dev-only restriction and lists the package-level edits and test updates. The checklist items are marked, and the AI…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: restricting useRouteContext inside pendingComponent to parent routes. The changeset adds an assertion in router-core and wires the pending route into the React, Solid, and Vue non-route component contexts. The title is specific and matches the changes in the raw summary and the PR objectives.

Full details: Description check

Explanation

The description follows the template. It has the Changes section, which explains the dev-only restriction and lists the package-level edits and test updates. The checklist items are marked, and the AI-assistance disclosure is present. Release Impact selects the changeset option. The description does not state the exact local commands run, but the template does not require them. Changes and checklist content are present, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between efe0044 and 9cbbe25.

Files selected for processing: 4

  • packages/react-router/tests/pending-route-context-access.test.tsx
  • packages/router-core/src/useRouteContext.ts
  • packages/solid-router/tests/pending-route-context-access.test.tsx
  • packages/vue-router/tests/pending-route-context-access.test.tsx
Files skipped from review as they are similar to previous changes: 3

  • packages/react-router/tests/pending-route-context-access.test.tsx
  • packages/solid-router/tests/pending-route-context-access.test.tsx
  • packages/vue-router/tests/pending-route-context-access.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

This pull request does not affect bundle size in any measured scenario.

@pkg-pr-new

pkg-pr-new Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 9cbbe25

@codspeed

codspeed Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 6.6%

2 warnings, 1 note

⚠️ 52 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

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 20 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

⚡ 3 improved benchmarks
✅ 197 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory mem server error-paths redirect (react) 14.2 KB 12.8 KB +10.87%
⚡ Memory mem server error-paths redirect (solid) 11.5 KB 11 KB +4.69%
⚡ Memory mem server error-paths error (vue) 136.9 KB 131.2 KB +4.37%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing t3/explain-non-route-context (9cbbe25) with main (10b22c2)

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