Skip to content

Commit 7f772d3

Browse files
authored
fix: Update higher-order-components callbacks per react-perf's warnings (#31022)
## **Description** Removes inline functions and objects that `eslint-plugin-react-perf` was flagging as bad for perf. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31022?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Nothing should change ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 8a31ac6 commit 7f772d3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

ui/helpers/higher-order-components/authenticated/authenticated.component.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import PropTypes from 'prop-types';
33
import { Redirect, Route } from 'react-router-dom';
44
import { UNLOCK_ROUTE, ONBOARDING_ROUTE } from '../../constants/routes';
55

6+
const OnboardingRoute = { pathname: ONBOARDING_ROUTE };
7+
const UnlockRoute = { pathname: UNLOCK_ROUTE };
8+
69
export default function Authenticated(props) {
710
const { isUnlocked, completedOnboarding } = props;
811
switch (true) {
912
case isUnlocked && completedOnboarding:
1013
return <Route {...props} />;
1114
case !completedOnboarding:
12-
return <Redirect to={{ pathname: ONBOARDING_ROUTE }} />;
15+
return <Redirect to={OnboardingRoute} />;
1316
default:
14-
return <Redirect to={{ pathname: UNLOCK_ROUTE }} />;
17+
return <Redirect to={UnlockRoute} />;
1518
}
1619
}
1720

ui/helpers/higher-order-components/feature-toggled-route.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import PropTypes from 'prop-types';
33
import { Redirect, Route } from 'react-router-dom';
44

55
export default function FeatureToggledRoute({ flag, redirectRoute, ...props }) {
6+
const redirect = useMemo(
7+
() => ({ pathname: redirectRoute }),
8+
[redirectRoute],
9+
);
610
if (flag) {
711
return <Route {...props} />;
812
}
9-
return <Redirect to={{ pathname: redirectRoute }} />;
13+
return <Redirect to={redirect} />;
1014
}
1115

1216
FeatureToggledRoute.propTypes = {

ui/helpers/higher-order-components/initialized/initialized.component.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import PropTypes from 'prop-types';
33
import { Redirect, Route } from 'react-router-dom';
44
import { ONBOARDING_ROUTE } from '../../constants/routes';
55

6+
const onboardingRoute = { pathname: ONBOARDING_ROUTE };
7+
68
export default function Initialized(props) {
79
return props.completedOnboarding ? (
810
<Route {...props} />
911
) : (
10-
<Redirect to={{ pathname: ONBOARDING_ROUTE }} />
12+
<Redirect to={onboardingRoute} />
1113
);
1214
}
1315

0 commit comments

Comments
 (0)