Skip to content

fix(react-router): keep relative link active when changing inherited param#6689

Merged
Sheraff merged 4 commits intomainfrom
codex/issue-5655-repro
Feb 18, 2026
Merged

fix(react-router): keep relative link active when changing inherited param#6689
Sheraff merged 4 commits intomainfrom
codex/issue-5655-repro

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Feb 17, 2026

Fix #5655

Summary

  • add a regression reproduction test for issue Link component active/inactive reactivity is not updated on param change #5655 in packages/react-router/tests/link.test.tsx
  • mirror the reported /post/$postId/step1 and /post/$postId/step2 behavior
  • assert the current broken active state for the relative Step 1 link with test.fails
  • fix new failing test by updating the subscription behavior of Link components

Bonus

  • found an opportunity to skip a buildLocation call during preloadRoute since Link components already have a built location on hand

Summary by CodeRabbit

  • Bug Fixes

    • Relative links keep their active state when inherited route parameters change, preserving correct active visuals during nested/dynamic navigation.
  • New Features

    • Link reactivity expanded to consider path, query, and hash so active status updates more accurately.
    • Preloading now accepts and uses a supplied pre-built location when available, improving preload accuracy with current navigation state.
  • Tests

    • Added cross-framework tests verifying active-state behavior for relative links with inherited params.

@Sheraff Sheraff changed the title fix(react-router): keep relative link active when changind inherited param fix(react-router): keep relative link active when changing inherited param Feb 17, 2026
@nx-cloud
Copy link

nx-cloud bot commented Feb 17, 2026

View your CI Pipeline Execution ↗ for commit 998fb9b

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

☁️ Nx Cloud last updated this comment at 2026-02-18 08:07:23 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 17, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 998fb9b

@Sheraff Sheraff marked this pull request as draft February 17, 2026 22:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

useLinkProps now subscribes to a composite built-location state (path/search/hash and inherited params) and passes that built location into route preloading. Router core's preloadRoute accepts an optional _builtLocation and uses it when provided. Tests added across frameworks to verify relative link active state with inherited param changes.

Changes

Cohort / File(s) Summary
React Link
packages/react-router/src/link.tsx
useLinkProps selector expanded to subscribe to built location state (path/search/hash + inherited params). Internal ref renamed to currentLocationState. Preload invocation now supplies _builtLocation and includes next in deps.
Router core
packages/router-core/src/router.ts
Public PreloadRouteFn options extended with optional _builtLocation?: ParsedLocation. preloadRoute now uses opts._builtLocation ?? this.buildLocation(opts as any).
Tests (React / Solid / Vue)
packages/react-router/tests/link.test.tsx, packages/solid-router/tests/link.test.tsx, packages/vue-router/tests/link.test.tsx
Added test case "keeps a relative link active when changing inherited params (issue #5655)" to verify relative link active state persists when inherited route params change and when switching posts. Tests exercise nested routes and param propagation.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant LinkHook as Link Hook (useLinkProps)
participant RouterCore as RouterCore
participant Preloader as preloadRoute
participant Routes as Route Matching

LinkHook->>RouterCore: buildLocation(next opts)
activate RouterCore
RouterCore-->>LinkHook: ParsedLocation (builtLocation)
LinkHook->>Preloader: preloadRoute(opts + _builtLocation)
activate Preloader
Preloader->>Routes: match/preload using _builtLocation
Routes-->>Preloader: matched route modules
Preloader-->>LinkHook: preload result
deactivate Preloader
deactivate RouterCore

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • schiller-manuel
  • nlynzaad

Poem

🐇 I nibble paths and stitch the hash,
I build your locations in a flash,
Links now hold when params rearrange,
Preloaded steps take a gentle change,
Hooray — I hop through routes so fast! 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: improving relative link active state behavior when inherited parameters change, which is the core issue addressed across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 codex/issue-5655-repro

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

@Sheraff Sheraff marked this pull request as ready for review February 17, 2026 23:46
@Sheraff Sheraff merged commit 99e3025 into main Feb 18, 2026
6 checks passed
@Sheraff Sheraff deleted the codex/issue-5655-repro branch February 18, 2026 08:56
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.

Link component active/inactive reactivity is not updated on param change

1 participant

Comments