Skip to content

[HOLD] Reposition three-dots popover menus after a viewport resize - #101077

Draft
MelvinBot wants to merge 3 commits into
mainfrom
claude-walletPopoverResizeReposition
Draft

MelvinBot wants to merge 3 commits into
mainfrom
claude-walletPopoverResizeReposition

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

When a popover menu is open and the viewport is resized, ThreeDotsMenu re-measures its anchor button in a useLayoutEffect and writes the result straight back as the popover's anchorPosition. On the Wallet page each row lives inside a FlashList, whose absolutely-positioned cells are re-laid-out asynchronously after the resize. On web measureInWindow resolves on a setTimeout(0), which lands before that re-layout — so the effect reads pre-resize coordinates and pins the open menu to a stale position. Nothing re-measures afterwards, so the popover stays detached from its row.

This is the same failure mode the Wallet page used to guard against itself: #32492 and later #62668 both repositioned the menu on resize, debounced by CONST.TIMING.RESIZE_DEBOUNCE_TIME. That page-level handler was removed when the popup moved into the generic ThreeDotsMenu, and nothing replaced it. CopilotPage.tsx still carries a working copy of the original pattern.

The fix puts that behavior back in the shared component rather than adding a third page-level copy:

  • src/components/ThreeDotsMenu/index.tsx — the re-measure is debounced by CONST.TIMING.RESIZE_DEBOUNCE_TIME so it runs once the surrounding layout has settled, and is cancelled on cleanup.
  • The reposition effect now depends on the viewport size and menu visibility only. It previously depended on getMenuPosition, which most callers give a new identity on every render (anchorAlignment is an inline object literal at nearly every call site), so the effect re-fired on every render and each run's setPosition produced a fresh object that triggered the next run — a self-sustaining render loop while a menu was open. getMenuPosition is now read through a ref, and setPosition keeps the previous object when the measurement is unchanged.
  • src/pages/settings/Wallet/WalletPage/index.tsx — removes paymentMethodButtonRef, the anchor ref that the deleted resize handler used to measure. It was still being assigned but never read.

Regression coverage lives with the shared component now, in tests/unit/ThreeDotsMenuRepositionTest.tsx.

Fixed Issues

$ #100882
PROPOSAL: #100882 (comment)

Tests

// TODO: The human co-author must fill out the tests they ran before marking this PR as "ready for review".
// Please describe what tests you performed that validate the change works.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
// TODO: The human co-author must fill out the QA steps before marking this PR as "ready for review".
// Please describe what QA needs to do to validate this change and which areas they should test for regressions.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

… a resize

Co-authored-by: Eugene Voloshchak <eVoloshchak@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team September 14, 2026 11:34
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Sep 14, 2026
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-walletPopoverResizeReposition
git checkout -b claude-walletPopoverResizeReposition upstream/claude-walletPopoverResizeReposition
git push -u origin claude-walletPopoverResizeReposition

Then you can close this PR and open a new one from your fork.

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/ThreeDotsMenu/index.tsx 94.52% <100.00%> (+0.40%) ⬆️
src/pages/settings/Wallet/WalletPage/index.tsx 0.00% <0.00%> (ø)
... and 12 files with indirect coverage changes

The PopoverMenu mock assigned the rendered anchorPosition to a module-level
object during render, which React Compiler rejects with 'This value cannot be
modified' under both Babel and OXC. Record renders with a jest.fn spy instead
and read the last open render's anchorPosition from its call log.

Also apply the oxfmt import-group spacing the formatter expects.

Co-authored-by: Eugene Voloshchak <eVoloshchak@users.noreply.github.com>
@MelvinBot

MelvinBot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ⚠️ partial

The PR's Tests section is still a TODO placeholder, so I ran the repro steps from the linked issue #100882, with the viewport resize done by rotating the emulator. The Wallet part could not be run: this test account has no bank account or card, and adding one hits a magic-code account-validation screen I can't clear. I exercised the same ThreeDotsMenu popover on a Workspaces list row instead, and it repositioned correctly through landscape and back to portrait with no errors. Note that on Android native the popover docks to the bottom of the screen rather than anchoring to the row, so this run does not exercise the stale-anchor-coordinates path that the fix targets — that path is web-specific and needs a web run to confirm.

App responsive and error-free after the rotation flow

Step Status
Open the app and navigate to Settings tab > Wallet; the Wallet page loadsWallet page rendered with "Bank accounts" and "Cards" sections, but no existing payment method rows — only "Add bank account" / "Add personal card" actions, so no row with a three-dots menu was available.
Wallet page loaded with no existing payment methods
✅
Tap a bank account / payment method row to open its context popoverNo payment method row existed to tap. Adding a bank account triggered a mandatory email magic-code validation screen, which I can't clear; the standalone Add Debit Card page is also hard-disabled in source (return <NotFoundPage />). Fell back to the Workspaces list row "More" three-dots button, which uses the same ThreeDotsMenu component — it opened a popover with Go to workspace / Duplicate workspace / Delete workspace.
Add bank account blocked by magic-code validation screen
Fallback: Workspace row three-dots popover open in portrait
❌
With the popover open, rotate to landscape; the popover is not detached, offset, or off-screenAfter rotating to landscape the popover re-rendered sized to the new viewport, fully on-screen, with all three menu items visible and not clipped or offset.
Popover after rotating to landscape
✅
Rotate back to portrait with the popover open; the popover is correctly positioned, not staleThe popover returned to the portrait layout, correctly re-sized and positioned with no stale offset or misalignment.
Popover after rotating back to portrait
✅
No console / redbox errors, and the app stays responsive while the menu is openNo redbox overlay, error banner, or freeze after either rotation. The UI tree responded immediately each time, the popover dismissed cleanly, and the Workspaces list rendered normally.
App responsive and error-free after the rotation flow
✅

view run · no recording available

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed and pushed in a75669e. Both failing checks came from the new test file this PR adds, tests/unit/ThreeDotsMenuRepositionTest.tsx — not from the ThreeDotsMenu change itself.

React Compiler Compliance — the PopoverMenu mock captured the rendered anchorPosition by assigning it to a module-level object during render, which both compilers reject with This value cannot be modified. Because only Babel still memoized the file, this also tripped the memoization-divergence rule (3 errors total). The mock now records each render through a jest.fn spy, and the assertion reads the last open render's anchorPosition from the call log — ThreeDotsMenuRepositionTest.tsx:34-38 and :78.

Oxfmt check — the file was missing the blank line oxfmt puts between the type-import and external import groups. Applied via npm run fmt.

All checks now pass except Check independent approval, which is just waiting on a human reviewer.

Verification run locally
Check Result
npm run react-compiler-compliance-check check <file> pass (exit 0, no divergence)
npm run fmt then git diff --exit-code pass (clean tree)
npm run lint -- <file> pass
npm test -- <file> pass (2/2)
npm run typecheck pass
npm run spell -- <file> pass

The first lint pass after the rewrite surfaced two more errors that I also fixed in the same commit: react/no-unused-prop-types (the mock no longer read anchorPosition once it forwarded the whole props object) and unicorn/prefer-array-find (.filter(…).at(-1) → .findLast(…)).

No production code changed — the diff is confined to the test file.

@MelvinBot

MelvinBot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ⚠️ partial

The PR's Tests section is still a TODO placeholder, so I ran the repro steps from the linked issue #100882. The Wallet-specific repro could not be run: this test account has no bank account or card, and adding one hits a "Validate your account" magic-code screen I can't clear. I exercised the same ThreeDotsMenu popover on the Workspace Overview "More" button instead — the popover stayed correctly anchored to its trigger through a resize down to 900x700 and back to 1280x800, with no detachment, stale offset, or freeze. Console output could not be captured because log inspection is unsupported on this web session, so "no JS console errors" is not directly proven.

Share modal opened from the popover after both resizes, confirming responsiveness

Step Status
Navigate to Settings > Wallet; the Wallet page loadsThe Wallet page rendered with the "Bank accounts" and "Cards" sections, but no existing payment method row was present on this test account. Clicking "Add bank account" immediately required a "Validate your account" magic-code screen, which I can't clear.
Wallet page with no existing payment methods
✅
Click a bank account / payment method row; a context popover opens anchored to that rowCould not be run on the Wallet page — no payment method row existed to click. Fell back to the "More" button on a newly created Workspace's Overview page, which renders the same ThreeDotsMenu component this PR changes. It opened a popover with Share / Delete, positioned directly below and aligned to the button.
ThreeDotsMenu popover open, anchored under the More button
⚠️
Resize the viewport with the popover open; the popover stays anchored, not stale or offsetAfter resizing from 1280x800 to 900x700, the popover stayed directly below the "More" button, which itself shifted left with the resized header. No detachment or stale offset.
Popover correctly re-anchored after first resize to 900x700
✅
Resize a second time with the popover open; it again tracks its anchorAfter resizing back to 1280x800, the popover snapped back under the "More" button, matching the pre-resize layout.
Popover correctly re-anchored after resizing back to 1280x800
✅
No JS console errors, and the page stays responsive while the menu is openConsole capture is unsupported on this web session, so literal console output could not be collected — the "no errors" half of this step is unverified. Responsiveness held: after both resizes the popover stayed live and interactive, and clicking "Share" from the still-open popover navigated to a fully rendered Share modal with no lag or stall, so no render loop or freeze.
Share modal opened from the popover after both resizes, confirming responsiveness
⚠️

view run · no recording available

@eVoloshchak

Copy link
Copy Markdown
Contributor

@MelvinBot, merge the latest main
Is this still reproducible? Were there PR's merged that would resolve this?

Co-authored-by: Eugene Voloshchak <eVoloshchak@users.noreply.github.com>

# Conflicts:
#	config/eslint/eslint.seatbelt.tsv
#	src/components/ThreeDotsMenu/index.tsx
@eVoloshchak

Copy link
Copy Markdown
Contributor

@codex, review

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Merged the latest main and pushed it in 922d9e09c.

Is it still reproducible? Based on the code, yes. On current main, the resize handler in src/components/ThreeDotsMenu/index.tsx:139-147 still re-measures right away, with no debounce. The Wallet page still has no resize handler of its own. I couldn't confirm it in the browser because the web dev server never loaded in this run.

Were there PRs merged that would fix it? No. Since this branch was created, the only ThreeDotsMenu change on main was a ref type change. The Wallet changes are unrelated features. The only other fix is Fix wallet popup not repositioning after a viewport resize, which is still open and changes the same component.

Merge conflict resolution
  • src/components/ThreeDotsMenu/index.tsx: kept both imports, main's ComponentRef and this PR's lodash/debounce.
  • config/eslint/eslint.seatbelt.tsv: took main's rows, but dropped the WalletPage no-unsafe-type-assertion entry. This PR removes both of those as HTMLDivElement casts.

I couldn't run lint or Jest locally because of sandbox limits. Existing tests failed the same way, so CI is the check here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 922d9e09cf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


afterEach(() => {
jest.useRealTimers();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add Given/When/Then sections to each new test

Both added it blocks omit the required literal // Given, // When, and // Then sections explaining why their setup, action, and assertions exist. Add all three documented sections to each test so this regression coverage follows the repository's mandatory test-documentation convention.

AGENTS.md reference: AGENTS.md:L1-L3

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T18:31:19.761571Z 922d9e0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

The failing check is unrelated to this PR, so I didn't push a change.

Analysis: test (job 7) fails one assertion at tests/ui/components/IOURequestStepConfirmationPageTest.tsx:1691 (Expected: "202", Received: undefined). This is a known flaky test. An earlier scan test leaves a 3-second fallback submit running, and it sometimes fires inside the "Report selection guard" tests. [No QA][Scan] Stop the untouched-scan test leaking a late submit into later tests fixes it and is still open.

Evidence
  • This PR changes only ThreeDotsMenu, WalletPage, the ESLint seatbelt file, and its own ThreeDotsMenuRepositionTest. The failing test renders the money request confirmation page and never touches these.
  • The same test failed with the same error on an unrelated branch (fix/96948-copyable-row-values) two minutes earlier.
  • The other failures (checklist, Check independent approval) are the human checklist and approval gates.

Next step: Re-run the failed job. It should pass, or it will once that fix PR merges.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Nothing has changed since my last comment, so there's still no fix to push. The ESLint check has since passed.

The only real failure is still test (job 7). It fails on the known flaky test in IOURequestStepConfirmationPageTest.tsx, which this PR doesn't touch. [No QA][Scan] Stop the untouched-scan test leaking a late submit into later tests fixes that flake.

Next step: Re-run the failed job here. I wasn't able to start the re-run myself. The other two failures (checklist and Check independent approval) clear once people complete the checklist and approve.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

HOLD Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants