App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-12-08] [$250] Web- Wallet - The popup moves is not repositioned properly after the window is resized

Open vincdargento opened this issue 2 months ago • 109 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.4.75-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from TestRail: https://github.com/Expensify/Expensify/issues/360448 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team

Action Performed:

  1. Open NewDot in the browser and log in
  2. Open the Settings tab > Wallet
  3. Click on the bank account to display the context popup
  4. Resize the viewport (open and close the browser developer tools pane)

Expected Result:

The popup is repositioned properly after the window is resized

Actual Result:

The popup is not repositioned properly after the window is resized

Workaround:

N/A

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

https://github.com/user-attachments/assets/51476942-43c0-421e-b4b3-904736f5b3e9

Issue OwnerCurrent Issue Owner: @eVoloshchak
Upwork Automation - Do Not Edit

vincdargento avatar Sep 10 '26 20:09 vincdargento

Proposal

What is the root cause of that problem?

The Wallet page used to own a reposition-on-resize handler for this popup. It was deleted in a refactor and nothing replaced it.

This is the third report of this exact bug on this exact page:

Report Fix What it did
Expensify/App#31706 (2023) Expensify/App#32492 (2024-01-02) Added Dimensions.addEventListener('change', …) in WalletPage to re-measure the anchor and reposition the open popup
Expensify/App#61801 (2025) Expensify/App#62668 (2025-05-29) Replaced the listener (stale closure) with useLayoutEffect(…, [windowWidth, windowHeight])
this issue — The handler no longer exists

Expensify/App#67326 ("Partially setup account", merged 2025-11-30) deleted src/pages/settings/Wallet/WalletPage/WalletPage.tsx (−727 lines) and moved the popup into the generic ThreeDotsMenu. The shouldListenForResize / setMenuPosition machinery went with it. Confirmed leftovers of the deleted handler: WalletPage/index.tsx:124 still declares paymentMethodButtonRef, assigns it at :155 and :244, and never reads it — it was the anchor the old handler measured.

Clicking the row now opens a ThreeDotsMenu (PaymentMethodListItem.tsx:157-172, mounted at :233-244), whose only reposition path is ThreeDotsMenu/index.tsx:137-145. That generic effect is weaker than the handler it replaced in two ways I can point at in code:

  1. It anchors at the origin when the width breakpoint is crossed. usePopoverPosition.ts:62-66 short-circuits to {horizontal: 0, vertical: 0, width: 0, height: 0} whenever isSmallScreenWidth is true. Chrome docks DevTools to the right by default, so "open the developer tools pane" shrinks the width — crossing the 800px breakpoint makes the recalculation return the origin instead of the row. That matches the original report's wording, "the popup moves to the side."
  2. The re-measure is no longer debounced. The old fix deliberately debounced by CONST.TIMING.RESIZE_DEBOUNCE_TIME — still defined at CONST/index.ts:2244 but now unused by any Wallet code. The generic effect measures via measureInWindow (async on web) on every dimension tick, while the row sits in a FlashList that re-lays-out its absolutely-positioned cells after the resize — so it can read pre-resize coordinates and write them straight back.

Its dependency array is also unstable: anchorAlignment is an inline object literal at PaymentMethodListItem.tsx:239 and calculatePopoverPosition isn't memoized, so the effect re-fires on every render and its timing relative to the resize is non-deterministic.

What changes do you think we should make in order to solve the problem?

Fix it in the shared components, not with a fourth Wallet-specific patch:

  1. In usePopoverPosition, stop returning the origin when recalculating for an already-open popover. Either measure regardless of screen width, or have the caller dismiss / switch to the bottom-docked variant when the viewport crosses into small-screen width, so it never renders anchored at 0,0.
  2. In ThreeDotsMenu, debounce the re-measure by CONST.TIMING.RESIZE_DEBOUNCE_TIME so it runs after the list has re-laid out, and stabilise the effect's dependencies (memoize anchorAlignment at the call site and calculatePopoverPosition in the hook) so it fires on dimension change rather than on every render.
  3. Delete the dead paymentMethodButtonRef in WalletPage/index.tsx.

CopilotPage.tsx:164-175 still carries a working copy of the original pattern, so it is a useful reference for expected behaviour — and a sign this logic should live in the shared component rather than being re-implemented per page.

What alternative solutions did you explore? (Optional)

Investigation details, and what I could not confirm

Confidence: medium. The archaeology is verified directly against the code and PR history. What I could not confirm is which link in the generic ThreeDotsMenu path fails at runtime — I traced the whole downstream chain (PopoverMenu's memo comparator deep-compares anchorPosition; PopoverWithMeasuredContentBase:121-198 recomputes from anchorPosition plus live window dimensions) and it does react to position changes, so I could not statically prove the failure point. The two mechanisms above are ranked candidates, not a confirmed single cause.

I attempted a browser repro to discriminate between them, but the test session failed to render (blank page, unrelated to this bug), so there is no runtime evidence in this analysis. Whoever picks this up should verify by opening the popup and then (a) shrinking height only, and (b) shrinking width across 800px, logging isSmallScreenWidth and the position state in ThreeDotsMenu. Case (b) failing while (a) passes confirms mechanism 1; both failing points at mechanism 2.

Alternative explanation considered and not ruled out: FlashList cell recycling. The rows moved from FlatList to @shopify/flash-list; a resize forces a re-layout, and a recycled cell could carry ThreeDotsMenu's open state onto a different row's anchor. Testing the same shouldSelfPosition menu outside a FlashList (the report header ⋯ menu) would isolate this.

Related issues: no open duplicates. The two prior reports, Expensify/App#31706 and Expensify/App#61801, are both closed.

Regression-test gap: the test that caught this only covers the Wallet page. Since the popup is now a shared component, the coverage should follow it there.

💡 Suggested AI code review rule

This is the third recurrence of the same bug class, and the codebase has at least three independently hand-written copies of the "reposition on resize" logic, so it may be worth a coding-standards rule so the AI reviewer catches the next one. Proposed for Expensify/App:

  • Rule: UI-4 — Anchored popovers must recompute their anchor position on viewport change
  • Condition: When a component stores a popover anchorPosition measured from a ref, it must recompute that position while the popover is open whenever the window dimensions change, and must never fall back to {0, 0} for an already-open popover. Flag any change that removes such a recompute without providing an equivalent — an anchor ref left assigned but never read is the fingerprint.
  • Why: Deleting the page-level resize handler leaves the popup pinned to pre-resize coordinates or anchored at the origin. Regressed three times on the same page: Expensify/App#31706 → Expensify/App#61801 → this issue.
  • Search pattern: usePopoverPosition|calculatePopoverPosition|measureInWindow|getBoundingClientRect feeding an anchorPosition prop, without windowWidth/windowHeight in the recompute effect's deps or a Dimensions.addEventListener('change'; plus removed hunks matching Dimensions.addEventListener\('change' or useLayoutEffect\(.*\[windowWidth, windowHeight\] near a popover.
  • Behaviour removed (❌): WalletPage.tsx:303-312 before the refactor
  • Working reference (✅): CopilotPage.tsx:164-175

If it's worth adding, a maintainer can open it as a draft PR in Expensify/App's coding-standards skill (next free number is UI-4).


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/100882) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run · no recording available

MelvinBot avatar Sep 10 '26 20:09 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak (External)

melvin-bot[bot] avatar Sep 10 '26 20:09 melvin-bot[bot]

Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

melvin-bot[bot] avatar Sep 10 '26 20:09 melvin-bot[bot]

@MelvinBot, implement this

eVoloshchak avatar Sep 14 '26 10:09 eVoloshchak

⏱️ Ran out of time before I could finish. This usually means the task was too complex or I got stuck exploring. Please try again with a more specific request or post in #melvinbot-ai.

Run details

MelvinBot avatar Sep 14 '26 11:09 MelvinBot

@eVoloshchak Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Sep 17 '26 21:09 melvin-bot[bot]

@eVoloshchak Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Sep 21 '26 21:09 melvin-bot[bot]

@MelvinBot, implement https://github.com/Expensify/App/issues/100882#issuecomment-5624992007

eVoloshchak avatar Sep 22 '26 18:09 eVoloshchak

🤖 Draft PR created: Fix wallet popup not repositioning after a viewport resize

Please mark it as "Ready for review" when it is ready for review.

What I changed — fixed it in the shared components rather than adding a fourth Wallet-specific patch:

  1. ThreeDotsMenu/index.tsx:143-160 now debounces the reposition measurement by CONST.TIMING.RESIZE_DEBOUNCE_TIME, so a resize collapses into one measurement taken after the layout has settled. Previously it re-measured on every intermediate dimension tick, which can read the anchor's pre-resize coordinates (the row lives in a FlashList that re-lays-out after the resize) and write them straight back. This matches the pattern already used by DatePicker/index.tsx:194-202 and CopilotPage.tsx:171-181.
  2. Stabilised that effect's dependencies — calculatePopoverPosition is memoized in usePopoverPosition.ts:66-81, and both anchorAlignment object literals (the ThreeDotsMenu default and the one in PaymentMethodListItem) are hoisted to module scope. The effect now fires on dimension change instead of on every render.
  3. Deleted the dead paymentMethodButtonRef in WalletPage/index.tsx:124. That also drops two grandfathered no-unsafe-type-assertion entries from the ESLint seatbelt.

What I deliberately did not change. The proposal's first mechanism — usePopoverPosition returning {horizontal: 0, vertical: 0} when isSmallScreenWidth — is not reachable as a mispositioning bug. When isSmallScreenWidth is true, Popover/index.tsx:146-149 renders a BOTTOM_DOCKED modal and explicitly passes popoverAnchorPosition={undefined}, so the origin value is never used for positioning. Changing it would be a no-op here and would alter behavior for every other popover, so I left it alone. That leaves the debounce/stale-measurement mechanism as the fix.

Checks I ran
  • npm run lint-changed — passed
  • npm run typecheck — passed
  • npm run react-compiler-compliance-check check <changed files> — passed
  • npm run spell-changed — passed (4 files, 0 issues)
  • npm test on the related suites (usePopoverPositionTest, RecentlyAddedSectionTest, SearchActionsBarCreateButtonTest, FocusTrapForModalTest) — 44 tests passed

⚠️ I could not verify this in a browser. The web test environment failed to come up in this run, so the fix has not been confirmed against the reported repro. Before marking the PR ready, please check: open the Wallet popup, then (a) shrink the height only and (b) shrink the width across the 800px breakpoint, and confirm the popup stays anchored to its row in both cases. Also worth a quick regression pass on other three-dots menus, since ThreeDotsMenu is shared.

One related leftover I left out of scope: WorkspaceInvoiceVBASection.tsx has the same dead paymentMethodButtonRef pattern (declared and assigned, never read).

MelvinBot avatar Sep 22 '26 18:09 MelvinBot

@eVoloshchak this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] avatar Sep 24 '26 21:09 melvin-bot[bot]

@eVoloshchak Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Sep 25 '26 21:09 melvin-bot[bot]

@eVoloshchak 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Sep 29 '26 21:09 melvin-bot[bot]

@eVoloshchak Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

melvin-bot[bot] avatar Oct 01 '26 21:10 melvin-bot[bot]

Checking https://github.com/Expensify/App/pull/101918

eVoloshchak avatar Oct 02 '26 14:10 eVoloshchak

@eVoloshchak Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Oct 05 '26 22:10 melvin-bot[bot]

@eVoloshchak Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Oct 07 '26 21:10 melvin-bot[bot]

@eVoloshchak this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

melvin-bot[bot] avatar Oct 08 '26 22:10 melvin-bot[bot]

@eVoloshchak Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Oct 09 '26 21:10 melvin-bot[bot]

This is no longer reproducible, but I can't find any PRs that would fix this. Let's confirm. @MelvinBot please add a retest label and put https://github.com/Expensify/App/pull/101077 on hold

https://github.com/user-attachments/assets/7f6c615a-bd1b-4ed4-b738-499c7140629b

eVoloshchak avatar Oct 12 '26 18:10 eVoloshchak

Done:


view run

MelvinBot avatar Oct 12 '26 18:10 MelvinBot