fix: Stabilize withRouterHooks props by memoizing params/location references#39311
Merged
DDDDDanica merged 10 commits intomainfrom Jan 30, 2026
Merged
fix: Stabilize withRouterHooks props by memoizing params/location references#39311DDDDDanica merged 10 commits intomainfrom
withRouterHooks props by memoizing params/location references#39311DDDDDanica merged 10 commits intomainfrom
Conversation
Copilot
AI
changed the title
[WIP] Memoize useParams and useLocation in withRouterHooks
Memoize withRouterHooks to stabilize params/location references
Jan 16, 2026
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Contributor
Builds ready [c1d5bd2]
UI Startup Metrics (1311 ± 118 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
c1d5bd2 to
0b2debf
Compare
withRouterHooks props by memoizing params/location references
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Contributor
Builds ready [1b9cbaf]
UI Startup Metrics (1350 ± 111 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
ui/helpers/higher-order-components/with-router-hooks/with-router-hooks.test.tsx
Show resolved
Hide resolved
ui/helpers/higher-order-components/with-router-hooks/with-router-hooks.test.tsx
Show resolved
Hide resolved
Contributor
Builds ready [05d31e2]
UI Startup Metrics (1303 ± 100 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Contributor
Builds ready [713ee5b]
UI Startup Metrics (1279 ± 108 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Contributor
Builds ready [7fd9991]
UI Startup Metrics (1307 ± 115 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
n3ps
approved these changes
Jan 28, 2026
DDDDDanica
approved these changes
Jan 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical performance issue where
useParams()anduseLocation()hooks return new object references on every render, even when values are identical. ThewithRouterHooksHOC was passing these unstable references directly to wrapped components, breakingReact.memooptimization and triggering cascade re-renders across ~40 components per cycle, with multiple cascade cycles (5+) per user action.What is the reason for the change?
The unstable object references from router hooks were causing unnecessary re-renders throughout the application, significantly slowing down all user actions.
What is the improvement/solution?
Added memoization to stabilize
paramsandlocationprop references:params: Track keys and values as separate string primitives to detect actual content changeslocation: Track individual properties (pathname, search, hash, state) to detect route changesuseMemoto return the same object reference when content hasn't changedChangelog
CHANGELOG entry: Fixed critical performance issue slowing down all user actions by stabilizing props references used in routes
Related issues
Part of Break Global Re-render Cascade epic
Manual testing steps
withRouterHooksno longer re-render unnecessarily when route values haven't changedScreenshots/Recordings
N/A - This is a performance optimization with no visible UI changes. The improvement is observable through React DevTools Profiler showing reduced re-render counts.
Pre-merge author checklist
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Note
Medium Risk
Touches a widely used routing HOC and changes how
locationupdates propagate (ignoringlocation.key), which could affect components that implicitly relied on key-based updates. Logic is straightforward and covered by new unit tests, but regressions would be broadly visible in navigation-related UI.Overview
withRouterHooksnow memoizes router-derived props so wrapped components receive referentially stableparamsandlocationvalues when their meaningful contents haven’t changed.This introduces a new
useShallowEqualityCheckhook for shallow-reference stabilization (used forparams) and addsuseLocationStableto keeplocationstable while intentionally ignoringlocation.keychanges. Tests were expanded to assert memoization behavior, precedence of explicitly passedparams/locationprops, and to cover edge cases like comma-containing param values and same-path navigations where onlylocation.keychanges.Written by Cursor Bugbot for commit 7fd9991. This will update automatically on new commits. Configure here.