-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix: Popover toggle #35746
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
fix: Popover toggle #35746
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/core-platform (2 files, +2 -2)
🎨 @MetaMask/design-system-engineers (1 files, +21 -20)
🧪 @MetaMask/qa (1 files, +7 -2)
🖥️ @MetaMask/wallet-ux (1 files, +19 -13)
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 https://metamask.github.io/test-dapp/Samples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [cdf9de2]
UI Startup Metrics (1200 ± 71 ms)
Benchmark value 25 exceeds gate value 23 for chrome browserify home mean firstReactRender Benchmark value 6 exceeds gate value 1 for chrome browserify home mean initialActions Benchmark value 255 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 34 exceeds gate value 33 for chrome browserify home p95 getState Benchmark value 13 exceeds gate value 1.2 for chrome browserify home p95 initialActions Benchmark value 23 exceeds gate value 17 for chrome browserify home p95 setupStore Benchmark value 35 exceeds gate value 29 for chrome webpack home mean getState Benchmark value 265 exceeds gate value 195 for chrome webpack home p95 getState Benchmark value 14 exceeds gate value 7 for chrome webpack home p95 initialActions Benchmark value 1452 exceeds gate value 1405 for firefox browserify home mean uiStartup Benchmark value 1252 exceeds gate value 1245 for firefox browserify home mean load Benchmark value 1252 exceeds gate value 1239 for firefox browserify home mean domContentLoaded Benchmark value 41 exceeds gate value 25 for firefox browserify home mean backgroundConnect Benchmark value 29 exceeds gate value 25 for firefox browserify home mean firstReactRender Benchmark value 6 exceeds gate value 1 for firefox browserify home mean initialActions Benchmark value 10 exceeds gate value 9 for firefox browserify home mean setupStore Benchmark value 1677 exceeds gate value 1660 for firefox browserify home p95 uiStartup Benchmark value 253 exceeds gate value 195 for firefox browserify home p95 domInteractive Benchmark value 120 exceeds gate value 70 for firefox browserify home p95 backgroundConnect Benchmark value 13 exceeds gate value 2 for firefox browserify home p95 initialActions Benchmark value 110 exceeds gate value 100 for firefox webpack home mean domInteractive Benchmark value 31 exceeds gate value 26 for firefox webpack home mean backgroundConnect Benchmark value 45 exceeds gate value 38 for firefox webpack home mean firstReactRender Benchmark value 8 exceeds gate value 1 for firefox webpack home mean initialActions Benchmark value 277 exceeds gate value 156 for firefox webpack home p95 domInteractive Benchmark value 57 exceeds gate value 50 for firefox webpack home p95 firstReactRender Benchmark value 7 exceeds gate value 2 for firefox webpack home p95 initialActions Sum of mean exceeds: 365ms | Sum of p95 exceeds: 601.8ms Sum of all benchmark exceeds: 966.8ms Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
cdf9de2
to
b9b1329
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 https://metamask.github.io/test-dapp/Samples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [b9b1329]
UI Startup Metrics (1234 ± 72 ms)
Benchmark value 26 exceeds gate value 23 for chrome browserify home mean firstReactRender Benchmark value 7 exceeds gate value 1 for chrome browserify home mean initialActions Benchmark value 1196 exceeds gate value 1190 for chrome browserify home p95 load Benchmark value 1188 exceeds gate value 1180 for chrome browserify home p95 domContentLoaded Benchmark value 261 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 15 exceeds gate value 1.2 for chrome browserify home p95 initialActions Benchmark value 950 exceeds gate value 940 for chrome browserify home p95 loadScripts Benchmark value 23 exceeds gate value 17 for chrome browserify home p95 setupStore Benchmark value 8 exceeds gate value 7 for chrome webpack home mean initialActions Benchmark value 2484 exceeds gate value 2454 for chrome webpack home p95 uiStartup Benchmark value 23 exceeds gate value 7 for chrome webpack home p95 initialActions Benchmark value 1441 exceeds gate value 1405 for firefox browserify home mean uiStartup Benchmark value 1242 exceeds gate value 1239 for firefox browserify home mean domContentLoaded Benchmark value 40 exceeds gate value 25 for firefox browserify home mean backgroundConnect Benchmark value 29 exceeds gate value 25 for firefox browserify home mean firstReactRender Benchmark value 6 exceeds gate value 1 for firefox browserify home mean initialActions Benchmark value 11 exceeds gate value 9 for firefox browserify home mean setupStore Benchmark value 1700 exceeds gate value 1660 for firefox browserify home p95 uiStartup Benchmark value 207 exceeds gate value 195 for firefox browserify home p95 domInteractive Benchmark value 96 exceeds gate value 70 for firefox browserify home p95 backgroundConnect Benchmark value 8 exceeds gate value 2 for firefox browserify home p95 initialActions Benchmark value 104 exceeds gate value 100 for firefox webpack home mean domInteractive Benchmark value 33 exceeds gate value 26 for firefox webpack home mean backgroundConnect Benchmark value 43 exceeds gate value 38 for firefox webpack home mean firstReactRender Benchmark value 6 exceeds gate value 1 for firefox webpack home mean initialActions Benchmark value 271 exceeds gate value 156 for firefox webpack home p95 domInteractive Benchmark value 51 exceeds gate value 50 for firefox webpack home p95 firstReactRender Benchmark value 10 exceeds gate value 2 for firefox webpack home p95 initialActions Sum of mean exceeds: 331ms | Sum of p95 exceeds: 540.8ms Sum of all benchmark exceeds: 871.8ms Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 https://metamask.github.io/test-dapp/Samples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [61f81d5]
UI Startup Metrics (1233 ± 67 ms)
Benchmark value 1065 exceeds gate value 1061 for chrome browserify home mean domContentLoaded Benchmark value 251 exceeds gate value 10 for chrome browserify home mean backgroundConnect Benchmark value 24 exceeds gate value 23 for chrome browserify home mean firstReactRender Benchmark value 5 exceeds gate value 1 for chrome browserify home mean initialActions Benchmark value 1182 exceeds gate value 1180 for chrome browserify home p95 domContentLoaded Benchmark value 1182 exceeds gate value 1180 for chrome browserify home p95 firstPaint Benchmark value 266 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 12 exceeds gate value 1.2 for chrome browserify home p95 initialActions Benchmark value 941 exceeds gate value 940 for chrome browserify home p95 loadScripts Benchmark value 15 exceeds gate value 7 for chrome webpack home p95 initialActions Benchmark value 1434 exceeds gate value 1405 for firefox browserify home mean uiStartup Benchmark value 36 exceeds gate value 25 for firefox browserify home mean backgroundConnect Benchmark value 28 exceeds gate value 25 for firefox browserify home mean firstReactRender Benchmark value 5 exceeds gate value 1 for firefox browserify home mean initialActions Benchmark value 13 exceeds gate value 9 for firefox browserify home mean setupStore Benchmark value 1678 exceeds gate value 1660 for firefox browserify home p95 uiStartup Benchmark value 235 exceeds gate value 195 for firefox browserify home p95 domInteractive Benchmark value 80 exceeds gate value 70 for firefox browserify home p95 backgroundConnect Benchmark value 8 exceeds gate value 2 for firefox browserify home p95 initialActions Benchmark value 50 exceeds gate value 27 for firefox browserify home p95 setupStore Benchmark value 106 exceeds gate value 100 for firefox webpack home mean domInteractive Benchmark value 32 exceeds gate value 26 for firefox webpack home mean backgroundConnect Benchmark value 44 exceeds gate value 38 for firefox webpack home mean firstReactRender Benchmark value 5 exceeds gate value 1 for firefox webpack home mean initialActions Benchmark value 266 exceeds gate value 156 for firefox webpack home p95 domInteractive Benchmark value 51 exceeds gate value 50 for firefox webpack home p95 firstReactRender Benchmark value 9 exceeds gate value 2 for firefox webpack home p95 initialActions Sum of mean exceeds: 325ms | Sum of p95 exceeds: 486.8ms Sum of all benchmark exceeds: 811.8ms Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
// Close the popover when the "Esc" key is pressed | ||
if (onPressEscKey) { | ||
onPressEscKey(); | ||
useEffect(() => { |
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.
- The event handlers where used in the useEffect but not in the deps array
) { | ||
if (onClickOutside) { | ||
onClickOutside(); | ||
const handleClickOutside = (event: MouseEvent) => { |
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.
- So we move them inside
isOpen && | ||
popoverRef.current && | ||
!popoverRef.current.contains(event.target as Node) && | ||
!referenceElement?.contains(event.target as Node) |
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.
- The trigger (reference) element was not being checked
ui/components/multichain/app-header/app-header-unlocked-content.tsx
Outdated
Show resolved
Hide resolved
…t.tsx Co-authored-by: Danica Shen <[email protected]>
📊 Page Load Benchmark ResultsCurrent Commit: 📄 https://metamask.github.io/test-dapp/Samples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [0dc8661]
UI Startup Metrics (1224 ± 66 ms)
Benchmark value 26 exceeds gate value 23 for chrome browserify home mean firstReactRender Benchmark value 5 exceeds gate value 1 for chrome browserify home mean initialActions Benchmark value 268 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 14 exceeds gate value 1.2 for chrome browserify home p95 initialActions Benchmark value 2757 exceeds gate value 2454 for chrome webpack home p95 uiStartup Benchmark value 2406 exceeds gate value 2030 for chrome webpack home p95 load Benchmark value 2386 exceeds gate value 2005 for chrome webpack home p95 domContentLoaded Benchmark value 218 exceeds gate value 195 for chrome webpack home p95 getState Benchmark value 20 exceeds gate value 7 for chrome webpack home p95 initialActions Benchmark value 2383 exceeds gate value 1970 for chrome webpack home p95 loadScripts Benchmark value 31 exceeds gate value 25 for firefox browserify home mean backgroundConnect Benchmark value 28 exceeds gate value 25 for firefox browserify home mean firstReactRender Benchmark value 4 exceeds gate value 1 for firefox browserify home mean initialActions Benchmark value 11 exceeds gate value 9 for firefox browserify home mean setupStore Benchmark value 229 exceeds gate value 195 for firefox browserify home p95 domInteractive Benchmark value 7 exceeds gate value 2 for firefox browserify home p95 initialActions Benchmark value 43 exceeds gate value 27 for firefox browserify home p95 setupStore Benchmark value 105 exceeds gate value 100 for firefox webpack home mean domInteractive Benchmark value 31 exceeds gate value 26 for firefox webpack home mean backgroundConnect Benchmark value 44 exceeds gate value 38 for firefox webpack home mean firstReactRender Benchmark value 5 exceeds gate value 1 for firefox webpack home mean initialActions Benchmark value 276 exceeds gate value 156 for firefox webpack home p95 domInteractive Benchmark value 53 exceeds gate value 50 for firefox webpack home p95 firstReactRender Benchmark value 13 exceeds gate value 2 for firefox webpack home p95 initialActions Sum of mean exceeds: 284ms | Sum of p95 exceeds: 1960.8ms Sum of all benchmark exceeds: 2244.8ms Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
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.
Are there unit tests for Popover that we need to change here to test for the bug we are fixing here? I guess the changes to the e2e tests covers this.
|
||
// This click will close the menu. | ||
await headerNavbar.openThreeDotMenu(); | ||
await headerNavbar.mouseClickOnThreeDotMenu(); |
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.
It looks like openThreeDotMenu
accounts for differences on Firefox vs. Chrome. Do we not need to do that anymore?
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.
The original test had a flaw itself, it called both methods when only 1 click really mattered because of the popover bug
setAccountOptionsMenuOpen((previous) => { | ||
const isMenuOpen = !previous; | ||
if (isMenuOpen) { | ||
trackEvent({ |
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.
Why are we creating a MetaMetrics event in a React state change handler? Shouldn't we do that afterward?
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.
@mcmire That is existing prod code - see line 143, tracking whenever the menu opens
Was trying to keep the focus of this PR about fixing the toggle
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.
Gotcha. Does this not work?
setAccountOptionsMenuOpen((previous) => !previous);
if (accountOptionsMenuOpen) {
trackEvent({
event: MetaMetricsEventName.NavMainMenuOpened,
category: MetaMetricsEventCategory.Navigation,
properties: {
location: 'Home',
},
});
}
Or does it make sense to move the tracking into a useEffect
?
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 non-blocking, I will let you decide, but just wanted to point it out in case there is a better way to do this)
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.
Calling
if (accountOptionsMenuOpen) {
trackEvent({
event: MetaMetricsEventName.NavMainMenuOpened,
category: MetaMetricsEventCategory.Navigation,
properties: {
location: 'Home',
},
});
}
directly like that will skew the tracking especially knowing the extension has existing excessive re-renders
useEffect might work but again susceptible to re-renders
IMO safest option without a full rewrite of this component and popover is the setState and logically close to the button click event
I mean we could also put events on the Menu component itself when it renders but I think these are for another PR
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.
Okay no problem!
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.
Snaps-related changes LGTM.
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.
Did not test but the code looks good.
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.
Great improvement, thanks for spotting this!
Description
Fixes the Popover so it can toggled by the same element that opened it
Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist