-
Notifications
You must be signed in to change notification settings - Fork 5.4k
refactor: use const for navigate(-1) and navigate('/'); also migrate the remaining files to v5-compat #37819
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
base: main
Are you sure you want to change the base?
Conversation
|
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. |
✨ Files requiring CODEOWNER review ✨🔑 @MetaMask/accounts-engineers (6 files, +38 -32)
👨🔧 @MetaMask/core-extension-ux (7 files, +24 -20)
💎 @MetaMask/metamask-assets (1 files, +5 -2)
🔔 @MetaMask/notifications (1 files, +0 -10)
|
ui/helpers/higher-order-components/with-router-hooks/with-router-hooks.tsx
Show resolved
Hide resolved
Builds ready [66acd3c]
UI Startup Metrics (1269 ± 105 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [b0a310d]
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
b0a310d to
12736f7
Compare
Builds ready [12736f7]
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [202a374]
UI Startup Metrics (1256 ± 106 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
996910f to
95d2990
Compare
Builds ready [6d381a4]
UI Startup Metrics (1293 ± 104 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
6d381a4 to
fce7555
Compare
6e7d162 to
70f27cf
Compare
| <ConnectedAccounts navigate={this.props.navigate} /> | ||
| </ScrollContainer> | ||
| ); | ||
| } |
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.
Bug: Routes removed breaking navigation to connected pages
The Route components for CONNECTED_ROUTE and CONNECTED_ACCOUNTS_ROUTE were removed and replaced with conditional rendering based on location.pathname. This breaks routing because these paths are now rendered inside the DEFAULT_ROUTE handler instead of being proper routes. The router won't match these URLs correctly, causing navigation issues. Users navigating to /connected or /connected/accounts will see the correct content but the router state will be incorrect, potentially breaking back navigation and other routing-dependent features.
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.
Builds ready [70f27cf]
UI Startup Metrics (1224 ± 99 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
5d86d7c to
b94e29a
Compare
Builds ready [b94e29a]
UI Startup Metrics (1185 ± 92 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
b94e29a to
faa950e
Compare
| </ScrollContainer> | ||
| ); | ||
| } | ||
|
|
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.
Bug: Manual route handling bypasses React Router
The Home component manually checks location.pathname and renders ConnectedSites and ConnectedAccounts components directly, bypassing React Router's routing system. These routes (CONNECTED_ROUTE and CONNECTED_ACCOUNTS_ROUTE) were previously handled by <Route> components but are now being rendered conditionally in the Home component's render method. This breaks proper route handling, prevents route transitions, and could cause navigation issues since these components are rendered outside the router context.
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.
same as above, this is not valid
faa950e to
62fcbcf
Compare
| <ConnectedAccounts navigate={this.props.navigate} /> | ||
| </ScrollContainer> | ||
| ); | ||
| } |
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.
Bug: Connected routes broken by incorrect routing architecture
The CONNECTED_ROUTE and CONNECTED_ACCOUNTS_ROUTE handling was moved from router-level Route components into the Home component's render method. However, Home is mounted at DEFAULT_ROUTE (/), so when users navigate to /connected or /connected/accounts, the router won't match the Home component at all. The conditional checks location?.pathname === CONNECTED_ROUTE will never be true because Home won't be rendered for these paths. These routes need to be restored in the router configuration or Home needs to be mounted at a parent route that can handle these child paths.
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.
This is not correct under our situation, the parent router in routes.component.tsx still uses v5's <Switch> which does prefix matching, so Home at path="/" matches /connected too, allowing our conditional rendering to work:
// routes.component.tsx - STILL using v5 <Switch> (not migrated yet)
<Switch>
<RouteWithLayout path={DEFAULT_ROUTE} /* "/" */ layout={RootLayout}>
{createV5CompatRoute(Home, { includeNavigate: true, includeLocation: true })}
</RouteWithLayout>
</Switch>
// home.component.js - uses v5-compat navigate/location props
if (location?.pathname === '/connected') return <ConnectedSites navigate={navigate} />;
if (location?.pathname === '/connected/accounts') return <ConnectedAccounts navigate={navigate} />;
return <HomeContent />; // default for '/'
We're mixing v5 routing structure (Switch) with v5-compat navigation (useNavigate, useLocation) - that's why we can't use nested <Routes> inside Home yet. And this will be removed by v6
Builds ready [62fcbcf]
UI Startup Metrics (1223 ± 93 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [15d2ea2]
UI Startup Metrics (1218 ± 105 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [8e8a6d3]
UI Startup Metrics (1222 ± 98 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [f76f9b5]
UI Startup Metrics (1261 ± 109 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [dc9beda]
UI Startup Metrics (1207 ± 106 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Description
Changelog
CHANGELOG entry: null
Related issues
Fixes: partial is for https://github.com/MetaMask/MetaMask-planning/issues/6231
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Replace history-based navigation with v5-compat navigate and PREVIOUS_ROUTE/DEFAULT_ROUTE across the app, updating routing scaffolding, components, hooks, tests, and stories.
navigatebridge inroutes.component.tsx; passnavigate,location, andparamsto v5-compat components via helpers.navigate(-1)withnavigate(PREVIOUS_ROUTE); standardize uses ofDEFAULT_ROUTEand other route constants.react-router-dom-v5-compatAPIs (useNavigate,useLocation,useMatch,matchPath) across files.navigateinstead ofhistory(e.g.,Alerts,InvalidCustomNetworkAlert,HideTokenConfirmationModal,NicknamePopover, SRP-related components, NFT image view, transaction details, permissions page, snaps list/view, home, connected accounts/sites, asset options/token asset, notifications settings, wallet/account details).PREVIOUS_ROUTEfor back actions (e.g., SRP flows, bridge tx details, send hooks, confirm flows).useClaimState,useCurrentAsset,useSegmentContext).utils.jsroute matching to v5-compatmatchPathsignature.DEFAULT_ROUTE,PREVIOUS_ROUTE); adjust mocks accordingly.navigateargs.rewardsslice (remove extraneous whitespace).Written by Cursor Bugbot for commit dc9beda. This will update automatically on new commits. Configure here.