Skip to content

Commit f8aa45e

Browse files
authored
feat: removed transition from drawer while going back to home page (MetaMask#40432)
This PR is to remove the transition for when a user is navigating back from a page to home page ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/40432?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: ## **Manual testing steps** 1. Run extension 2. Click on hamburger menu, drawer opens with transition 3. Click on Dapp Connections in drawer and then click on back button in connections page 4. It should navigate back to home page, no transition from drawer should be there ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** https://github.com/user-attachments/assets/50a47731-3001-4596-a96a-12dde4150b4f ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk UI-only change that tweaks drawer animation state/cleanup; main risk is subtle regressions in open/close timing due to new previous-state tracking and RAF cancellation. > > **Overview** > **Drawer open behavior is adjusted to avoid unwanted transitions on navigation.** `GlobalMenuDrawer` now tracks the previous `isOpen` state and only plays the *enter* animation when transitioning from closed→open (e.g., hamburger click); when mounting/restoring with `isOpen` already true, it renders directly in the `open` phase. > > It also tightens transition cleanup by cancelling pending `requestAnimationFrame` callbacks on close/unmount and ensuring the phase/transform logic stays consistent during enter/exit. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 618954a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 933cd09 commit f8aa45e

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

ui/components/multichain/global-menu-drawer/global-menu-drawer.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const GlobalMenuDrawer = ({
6161
const exitTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
6262
const enterFrameRef = useRef<number | null>(null);
6363
const wasOpenRef = useRef(false);
64+
/** Tracks previous isOpen so we can run enter transition only when opening from closed (hamburger), not when mounting/restoring with open (back from page). */
65+
const prevIsOpenRef = useRef<boolean | undefined>(undefined);
6466
const rootLayoutRef = useRef<HTMLElement | null>(null);
6567
const appContainerRef = useRef<HTMLElement | null>(null);
6668
const resizeTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
@@ -69,30 +71,35 @@ export const GlobalMenuDrawer = ({
6971
const hasPosition = Object.keys(drawerStyle).length > 0;
7072
const readyToShow = isOpen && (!usePortal || hasPosition);
7173

72-
// Custom transition: only start when we can show (have position in portal mode).
74+
// Open drawer: use entering transition only when going from closed to open (hamburger click). When mounting or returning from a page with drawerOpen in URL, show immediately.
7375
useEffect(() => {
7476
if (readyToShow) {
7577
wasOpenRef.current = true;
7678
if (exitTimeoutRef.current !== null) {
7779
clearTimeout(exitTimeoutRef.current);
7880
exitTimeoutRef.current = null;
7981
}
80-
setDrawerPhase('entering');
81-
enterFrameRef.current = requestAnimationFrame(() => {
82+
const wasClosed = prevIsOpenRef.current === false;
83+
if (wasClosed) {
84+
setDrawerPhase('entering');
8285
enterFrameRef.current = requestAnimationFrame(() => {
83-
enterFrameRef.current = null;
84-
setDrawerPhase('open');
86+
enterFrameRef.current = requestAnimationFrame(() => {
87+
enterFrameRef.current = null;
88+
setDrawerPhase('open');
89+
});
8590
});
86-
});
87-
return () => {
88-
if (enterFrameRef.current !== null) {
89-
cancelAnimationFrame(enterFrameRef.current);
90-
enterFrameRef.current = null;
91-
}
92-
};
91+
} else {
92+
setDrawerPhase('open');
93+
}
94+
prevIsOpenRef.current = true;
9395
}
9496
if (wasOpenRef.current && !isOpen) {
9597
wasOpenRef.current = false;
98+
prevIsOpenRef.current = false;
99+
if (enterFrameRef.current !== null) {
100+
cancelAnimationFrame(enterFrameRef.current);
101+
enterFrameRef.current = null;
102+
}
96103
setDrawerPhase('exiting');
97104
exitTimeoutRef.current = setTimeout(() => {
98105
exitTimeoutRef.current = null;
@@ -105,12 +112,20 @@ export const GlobalMenuDrawer = ({
105112
}
106113
};
107114
}
108-
return undefined;
115+
if (!isOpen) {
116+
prevIsOpenRef.current = false;
117+
}
118+
return () => {
119+
if (enterFrameRef.current !== null) {
120+
cancelAnimationFrame(enterFrameRef.current);
121+
enterFrameRef.current = null;
122+
}
123+
};
109124
}, [isOpen, readyToShow]);
110125

111126
const isDrawerMounted = drawerPhase !== null;
112-
const isExiting = drawerPhase === 'exiting';
113127
const isEntering = drawerPhase === 'entering';
128+
const isExiting = drawerPhase === 'exiting';
114129
const isDrawerOpen = drawerPhase === 'open';
115130

116131
useLayoutEffect(() => {
@@ -286,7 +301,7 @@ export const GlobalMenuDrawer = ({
286301

287302
const backdropOpacity = isDrawerOpen ? 1 : 0;
288303
const panelTransform =
289-
isEntering || isExiting ? 'translateX(100%)' : 'translateX(0)';
304+
isExiting || isEntering ? 'translateX(100%)' : 'translateX(0)';
290305

291306
const dialogContent = isDrawerMounted ? (
292307
<div

0 commit comments

Comments
 (0)