-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(react-router, solid-router): reduce useNavigate reactivity on path changes #5037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughRemoves useActiveLocation from React and Solid packages, switches Link/useNavigate to use static/options.from instead of deriving from router location, adds a Solid Navigate helper, and introduces extensive /relative e2e route trees, components, and Playwright tests for React and Solid. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as Link Component
participant useLink as useLinkProps
participant Router as Router
UI->>useLink: initialize/link props
useLink->>useLink: compute from = options.from
useLink->>Router: buildLocation({ from, to, search, hash })
Router-->>useLink: location/href
UI-->>UI: render anchor with href
sequenceDiagram
autonumber
participant Caller as Component (useNavigate)
participant useNav as useNavigate
participant Router as Router
Caller->>useNav: call navigate(opts)
useNav->>useNav: from = opts.from ?? _defaultOpts?.from
useNav->>Router: router.navigate({ from, to, params, search, ... })
Router-->>useNav: navigation result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (40)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
View your CI Pipeline Execution ↗ for commit 348c965
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-plugin
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-plugin
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-server-functions-client
@tanstack/start-server-functions-fetcher
@tanstack/start-server-functions-server
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 9
🧹 Nitpick comments (1)
packages/solid-router/src/link.tsx (1)
14-14: Consistency nit: avoid mixed import/namespace usage for createMemo.Use Solid.createMemo everywhere and drop the named import.
-import { createMemo } from 'solid-js' +// use Solid.createMemo for consistency- const from = createMemo(() => { + const from = Solid.createMemo(() => {Also applies to: 147-147
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
packages/react-router/src/link.tsx(2 hunks)packages/react-router/src/useActiveLocation.ts(0 hunks)packages/react-router/src/useNavigate.tsx(2 hunks)packages/solid-router/src/link.tsx(2 hunks)packages/solid-router/src/useActiveLocation.ts(0 hunks)packages/solid-router/src/useNavigate.tsx(2 hunks)
💤 Files with no reviewable changes (2)
- packages/solid-router/src/useActiveLocation.ts
- packages/react-router/src/useActiveLocation.ts
🧰 Additional context used
🧬 Code graph analysis (4)
packages/react-router/src/link.tsx (2)
packages/react-router/src/useMatch.tsx (1)
useMatch(78-119)packages/router-core/src/utils.ts (1)
last(187-189)
packages/react-router/src/useNavigate.tsx (2)
packages/react-router/src/useMatch.tsx (1)
useMatch(78-119)packages/router-core/src/utils.ts (1)
last(187-189)
packages/solid-router/src/link.tsx (3)
packages/solid-router/src/useRouterState.tsx (1)
useRouterState(20-36)packages/solid-router/src/useMatch.tsx (1)
useMatch(55-96)packages/router-core/src/utils.ts (1)
last(187-189)
packages/solid-router/src/useNavigate.tsx (3)
packages/solid-router/src/useMatch.tsx (1)
useMatch(55-96)packages/router-core/src/link.ts (1)
NavigateOptions(289-295)packages/router-core/src/utils.ts (1)
last(187-189)
🪛 ESLint
packages/react-router/src/useNavigate.tsx
[error] 45-45: Definition for rule 'react-hooks/exhaustive-deps' was not found.
(react-hooks/exhaustive-deps)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
packages/react-router/src/link.tsx(1 hunks)packages/react-router/src/useNavigate.tsx(1 hunks)packages/solid-router/src/link.tsx(1 hunks)packages/solid-router/src/useNavigate.tsx(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/react-router/src/link.tsx
- packages/solid-router/src/link.tsx
- packages/react-router/src/useNavigate.tsx
🧰 Additional context used
🪛 ESLint
packages/solid-router/src/useNavigate.tsx
[error] 2-2: 'last' is defined but never used.
(unused-imports/no-unused-imports)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test
🔇 Additional comments (1)
packages/solid-router/src/useNavigate.tsx (1)
23-24: Ignore the non-reactive fallback suggestion—core already defaults “from” to the current path when omitted.
ThebuildLocationlogic usesconst defaultedFromPath = dest.unsafeRelative === 'path' ? currentLocation.pathname : (dest.from ?? lastMatch.fullPath)so when
options.fromand_defaultOpts.fromare bothundefined, it falls back tolastMatch.fullPath(the current route) without any subscriptions.Likely an incorrect or invalid review comment.
There was a problem hiding this 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
🧹 Nitpick comments (1)
packages/solid-router/src/useNavigate.tsx (1)
27-43: Consider delegating touseNavigate()for consistency and future-proofing.Using the hook here would centralize “from” handling and keep this component aligned if hook semantics evolve. Optional, but reduces duplication.
-export function Navigate< +export function Navigate< TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = '', >(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null { - const { navigate } = useRouter() + const navigate = useNavigate() Solid.onMount(() => { - navigate({ - ...props, - }) + // If the hook adopts additional defaults (e.g. "from" omission), + // this call will automatically benefit from them. + navigate(props as any) }) return null }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/react-router/src/link.tsx(1 hunks)packages/solid-router/src/useNavigate.tsx(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/react-router/src/link.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (2)
packages/solid-router/src/useNavigate.tsx (2)
27-33: TS version supportsconstgenerics
Repo’s root package.json pins TypeScript to ^5.9.0 (≥5.3) and other exports (e.g.createLink<const TComp>) already useconsttype parameters, so this is safe.
19-23: Drop the conditional inclusion offrom— passingfrom: undefinedfalls back to the correct path automaticallyLikely an incorrect or invalid review comment.
|
Todo: add some e2e tests before merging. Will merge later tonight |
This is a follow-up to #4978.
As picked up by @Sheraff the changes made caused useNavigate to negatively impact performance specifically with useNavigate being too reactive to path changes.
This reverts the use of useActiveLocation, that acted as a single implementation of the logic to determine the from location, and moves the determination of the from path back to each of Link and useNavigate. While the core logic is still the same across the implementations the implication of how it's used and the sources of the required inputs are different enough that it warrants separate implementations.
This PR does not revert the full change set and still applies to core reasons and changes for the previous commit in keeping the logic for determining the from clause the same, i.e. the order of determining the from path for navigation remains: from clause => current location => rendered location.
@Sheraff to advise if this implementation resolves the issues he picked up.
Summary by CodeRabbit