You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-07-06] [$250] Bug: Approve button flickers (disappears, reappears, disappears) when approving a report from workspace chat report preview #93067
When approving a report from the workspace chat report preview, the approve button flickers — it disappears, reappears, then disappears again instead of cleanly transitioning away after the action.
Steps to reproduce
Open a workspace chat report preview for a report that is pending approval.
Tap/click the Approve button.
Observe the button: it disappears, briefly reappears, then disappears again.
Expected behavior
The approve button should disappear cleanly (once) after tapping, as the report transitions to an approved state.
Actual behavior
The approve button disappears, reappears momentarily, then disappears again — a visible flicker.
Notes from investigation
Reproduced on a normal workspace; could not reproduce on the DEW policy.
Not consistently reproducible across all reports in a workspace.
Suspected cause: the Onyx update for the report status may be racing with the animation/UI timeout — the optimistic update may not always fire fast enough (or is being overwritten/re-evaluated) before the button re-renders.
Platform
Android
iOS
Web
Desktop
Issue OwnerCurrent Issue Owner: @mallenexpensifyUpwork Automation - Do Not Edit
Please re-state the problem that we are trying to solve in this issue.
Approving a report from the workspace chat report preview makes the action button flicker — it disappears, briefly reappears, then disappears again instead of transitioning away cleanly. It reproduces only on normal workspaces (not DEW) and only intermittently.
What is the root cause of that problem?
There are two independent conditions that drive which button the preview shows, and on approval they flip in separate render commits, leaving a one-frame gap where neither is active.
Otherwise it evaluates canApprove, which requires isProcessingReport (stateNum === SUBMITTED && statusNum === SUBMITTED).
The two state sources update through different channels — the React flag via setState, the report status via Onyx's async broadcast — so their commits can interleave. When the optimistic Onyx update lands in a render before the animation flag does, that intermediate render has canApprove === false (report is now APPROVED) andisApprovedAnimationRunning === false, so the action falls through to PAY/VIEW and the green Approve button vanishes. The next render applies the animation flag → the animated button reappears, then onAnimationFinish → stopAnimation clears it and it settles away. That is the disappear → reappear → disappear flicker.
This matches both reported quirks:
No flicker on DEW — DEW skips the optimistic stateNum/statusNum update, so canApprove never flips out from under the animation; the animation flag is the only driver and the transition stays smooth.
Intermittent — it's a render-ordering race; sometimes the flag commits first (smooth), sometimes the Onyx update does (flicker).
What changes do you think we should make in order to solve the problem?
Eliminate the gap between "approve condition true" and "animation flag true" so the slot is never empty:
Set the animation flag synchronously relative to the optimistic Onyx write so the flag-driven render always commits first — e.g. wrap startApprovedAnimation() in ReactDOM.flushSync (or flush it before calling API.write), guaranteeing the PAY/animated-button render lands before the report-status change can.
Or close the gap in getReportPreviewAction: keep returning the animated button for a report that just became APPROVED until the animation completes, rather than depending solely on the React flag winning the race.
A maintainer should confirm the exact scheduling with a local repro before settling on the approach.
Confidence & verification notes
Confidence: Medium. The trigger (optimistic stateNum/statusNum flip) is confirmed by code and corroborated by the DEW non-repro. The mechanism (getReportPreviewAction switching between canApprove and isApprovedAnimationRunning, rendered by two different button components — plain ApproveActionButton vs animated PayActionButton) is confirmed by code. The exact render-timing interleave that loses the race is the one piece not yet confirmed at runtime — worth verifying with React profiler / Onyx update logging in a local repro before implementing.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/93067) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
🚨 Edited by proposal-police: This proposal was edited at 2026-06-09 13:11:08 UTC.
Proposal
What is the root cause of that problem?
The workspace chat report preview can re-enable the Approve action after the local approved animation finishes because the preview only suppresses approval from report state or DEW-only pending metadata.
In ReportPreviewActionUtils.canApprove(), the preview returns APPROVE when the report is still processing, approval is enabled, current user is the manager, and the report has transactions. The only pending-approve guard is hasPendingDEWApprove(), which explicitly ignores non-DEW policies:
This is different from the search approval flow, which already marks every approved report with REPORT_METADATA.pendingExpenseAction = APPROVE and clears it on success/failure:
// If we are on the 'Approve', `Unapproved cash` or the `Unapproved company cards` suggested search, remove the report from the view once the action is taken, don't wait for the view to be re-fetched via Search
git blame shows the preview canApprove() / animation action selection lines came from commit 73665ddcb44, while the approve-flow metadata write came from 021f04d8673. The local checkout is grafted/shallow, so full git show --stat is noisy, but targeted line history confirms the current asymmetry.
What changes do you think we should make in order to solve the problem?
Use the same pending-approve metadata pattern for the single report approval flow, but keep the change scoped so DEW-specific UI does not regress.
In approveMoneyRequest(), enqueue the optimistic Onyx update before starting the animation.
Set REPORT_METADATA[reportID].pendingExpenseAction = APPROVE for all policies, not only DEW.
Clear that metadata in both success and failure data.
In ReportPreviewActionUtils.canApprove(), suppress Approve when reportMetadata.pendingExpenseAction === APPROVE. Do not change hasPendingDEWApprove() globally, because other places use it for DEW-specific messages/next-step behavior.
This should not regress DEW because DEW already uses the same metadata value. It should not regress search because search already sets and clears the same metadata for normal approvals. It is scoped to preview approve eligibility, so existing DEW-only display logic that uses hasPendingDEWApprove() keeps the same behavior.
What alternative solutions did you explore? (Optional)
Only moving onApproved?.() after API.write() reduces the race, but it still leaves the preview dependent on report state updates only.
Changing hasPendingDEWApprove() to ignore the DEW flag would be broader than needed and could affect DEW-specific next-step/system-message logic. A local pending-approve guard in the preview action utility is safer.
🚨 Edited by proposal-police: This proposal was edited at 2026-06-09 13:22:15 UTC.
Proposal
What is the root cause of that problem?
The workspace chat preview derives the button from the expense report's current policy and report state, but the preview approval path can submit the approve workflow with a different policy.
In ApproveActionButton and the approve branch of PayActionButton, the component reads the expense report policy, but passes policy: activePolicy into approveMoneyRequest(). The hold-menu submit path does the same. approveMoneyRequest() then uses that policy to decide whether the report is a DEW report and whether to optimistically update stateNum, statusNum, and managerID.
So if the active workspace policy is not the same as the report's policy, especially when the active policy is DEW and the report being approved is a normal workspace report, the approve action takes the DEW optimistic path and does not update the report status/manager. Meanwhile getReportPreviewAction() evaluates the real report policy, sees a normal submitted report that is still assigned to the current approver, and returns APPROVE again as soon as the short approved animation stops. When the backend update finally arrives, the button disappears again.
What changes do you think we should make in order to solve the problem?
Make approval workflow decisions use the expense report's own policy, not the currently active workspace policy.
Concretely:
In the report-preview approval callers (ApproveActionButton, the approve branch in PayActionButton, and the held-expense submit path used by the preview), pass the expense report policy as the workflow policy when calling approveMoneyRequest().
As a defensive cleanup in approveMoneyRequest(), use expenseReportPolicy as the canonical workflow policy for DEW detection, optimistic next-step generation, duplicate checks, and hold approval data. Keep the separate billing restriction check on expenseReportPolicy.
Do not change payment/KYC paths that legitimately need the active policy for payment setup.
Preserve actual DEW behavior: DEW reports should still use pendingExpenseAction and wait for backend confirmation; normal reports should optimistically update stateNum, statusNum, and managerID.
Add regression coverage for approving a normal report while NVP_ACTIVE_POLICY_ID points to a DEW policy, verifying that the normal optimistic report update is still applied and getReportPreviewAction() does not return APPROVE again after the animation flag clears.
I would also mirror the predicted approval state into the parent REPORT_PREVIEW action's childStateNum, childStatusNum, and, when forwarded, childManagerAccountID, matching the pay/reopen/retract patterns. That keeps the preview status display in sync, but the main flicker fix is using the report policy for the approve workflow.
What alternative solutions did you explore? (Optional)
A local "just approved" latch in the preview can hide the flicker, but it only masks the stale action selection. It would still let approveMoneyRequest() build optimistic data from the wrong policy and would need extra failure-clearing logic to avoid hiding a legitimate retry. Fixing the policy source addresses the state mismatch directly.
changed the title [-]Bug: Approve button flickers (disappears, reappears, disappears) when approving a report from workspace chat report preview[/-][+][$250] Bug: Approve button flickers (disappears, reappears, disappears) when approving a report from workspace chat report preview[/+]on Jun 9, 2026
⚠️@KJ21-ENG Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
The visibility of the Approve button is driven by two independent state sources that are never synchronized, and getReportPreviewAction evaluates them in sequence — the local animation flag first, then the Onyx report status:
onApproved sets isApprovedAnimationRunning = true (local React state), while API.write flips the report's stateNum/statusNum to approved/submitted in Onyx — a broadcast that propagates in a later render than the local setState. So the suppression of the button bounces between two sources:
while isApprovedAnimationRunning is true → returns PAY (the animated button), so Approve is hidden;
once canApprove sees the approved report → returns VIEW, so Approve is hidden.
The animation flag is reset on a fixed animation timer, independent of Onyx, when the settlement animation finishes:
If that timer-driven reset lands in a render where the optimistic status hasn't yet propagated (or is momentarily overwritten by successData), canApprove is still true → the Approve button reappears, then disappears again once Onyx settles. This is a race, hence "not consistently reproducible." On a DEW policy it can't reproduce because approveMoneyRequest skips the stateNum update and instead sets reportMetadata.pendingExpenseAction, which makes canApprove short-circuit deterministically via hasPendingDEWApprove — there is no racing second source.
What changes do you think we should make in order to solve the problem?
Make the button suppression come from a single source of truth so there is no window where canApprove is re-evaluated as true. Tie the lifetime of isApprovedAnimationRunning to the Onyx report state instead of the fixed animation timer: keep it true until the report is actually observed as approved/submitted, so by the time the flag clears, canApprove already returns false.
Concretely, onAnimationFinish should not unconditionally reset the flag here:
buttonMarginTop.set(shouldAddTopMargin ? gap : 0);
onAnimationFinish();
};
Instead defer stopAnimation until the optimistic approval has propagated (e.g. gate the reset on isReportApproved/!isProcessingReport for the report), so the animation flag and the Onyx status hand off cleanly with no overlap gap.
What alternative solutions did you explore? (Optional)
Mirror the DEW path for normal workspaces: have canApprove also return false while an optimistic approve is pending (a pending flag on the report/metadata, the same mechanism that already makes DEW immune):
Activity
MelvinBot commentedon Jun 9, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
Approving a report from the workspace chat report preview makes the action button flicker — it disappears, briefly reappears, then disappears again instead of transitioning away cleanly. It reproduces only on normal workspaces (not DEW) and only intermittently.
What is the root cause of that problem?
There are two independent conditions that drive which button the preview shows, and on approval they flip in separate render commits, leaving a one-frame gap where neither is active.
When you press Approve,
approveMoneyRequestdoes two things:onApproved?.()→startApprovedAnimation()→ sets the React stateisApprovedAnimationRunning = true.API.write(...)withoptimisticDatathat flips the report to APPROVED (stateNum/statusNum).The displayed button is chosen by
getReportPreviewAction:isApprovedAnimationRunningis true → returnsPAY(renders theAnimatedSettlementButton).canApprove, which requiresisProcessingReport(stateNum === SUBMITTED && statusNum === SUBMITTED).The two state sources update through different channels — the React flag via
setState, the report status via Onyx's async broadcast — so their commits can interleave. When the optimistic Onyx update lands in a render before the animation flag does, that intermediate render hascanApprove === false(report is now APPROVED) andisApprovedAnimationRunning === false, so the action falls through to PAY/VIEW and the green Approve button vanishes. The next render applies the animation flag → the animated button reappears, thenonAnimationFinish→stopAnimationclears it and it settles away. That is the disappear → reappear → disappear flicker.This matches both reported quirks:
stateNum/statusNumupdate, socanApprovenever flips out from under the animation; the animation flag is the only driver and the transition stays smooth.What changes do you think we should make in order to solve the problem?
Eliminate the gap between "approve condition true" and "animation flag true" so the slot is never empty:
startApprovedAnimation()inReactDOM.flushSync(or flush it before callingAPI.write), guaranteeing thePAY/animated-button render lands before the report-status change can.getReportPreviewAction: keep returning the animated button for a report that just became APPROVED until the animation completes, rather than depending solely on the React flag winning the race.A maintainer should confirm the exact scheduling with a local repro before settling on the approach.
Confidence & verification notes
Confidence: Medium. The trigger (optimistic
stateNum/statusNumflip) is confirmed by code and corroborated by the DEW non-repro. The mechanism (getReportPreviewActionswitching betweencanApproveandisApprovedAnimationRunning, rendered by two different button components — plainApproveActionButtonvs animatedPayActionButton) is confirmed by code. The exact render-timing interleave that loses the race is the one piece not yet confirmed at runtime — worth verifying with React profiler / Onyx update logging in a local repro before implementing.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/93067)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
mukhrr commentedon Jun 9, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-06-09 13:11:08 UTC.
Proposal
What is the root cause of that problem?
The workspace chat report preview can re-enable the
Approveaction after the local approved animation finishes because the preview only suppresses approval from report state or DEW-only pending metadata.In
ReportPreviewActionUtils.canApprove(), the preview returnsAPPROVEwhen the report is still processing, approval is enabled, current user is the manager, and the report has transactions. The only pending-approve guard ishasPendingDEWApprove(), which explicitly ignores non-DEW policies:App/src/libs/ReportPreviewActionUtils.ts
Lines 63 to 92 in 1cd4070
APPROVEafter animation stops:App/src/libs/ReportPreviewActionUtils.ts
Lines 224 to 245 in 1cd4070
App/src/libs/ReportActionsUtils.ts
Lines 389 to 390 in 1cd4070
The approve mutation starts the local animation before writing optimistic Onyx data:
onApproved?.()runs beforeAPI.write():App/src/libs/actions/IOU/ReportWorkflow.ts
Lines 752 to 754 in 1cd4070
stateNum/statusNumto hide approve:App/src/libs/actions/IOU/ReportWorkflow.ts
Lines 477 to 504 in 1cd4070
pendingExpenseAction: APPROVEis only set for DEW in this flow:App/src/libs/actions/IOU/ReportWorkflow.ts
Lines 533 to 540 in 1cd4070
This is different from the search approval flow, which already marks every approved report with
REPORT_METADATA.pendingExpenseAction = APPROVEand clears it on success/failure:App/src/libs/actions/Search.ts
Lines 669 to 680 in 1cd4070
App/src/libs/actions/Search.ts
Lines 689 to 718 in 1cd4070
History checked:
git log -S"pendingExpenseAction: CONST.EXPENSE_PENDING_ACTION.APPROVE"points to PR [NOQA] perf: narrow mount-time work in IOURequestStepAmount #92775, merged June 9, 2026: [NOQA] perf: narrow mount-time work in IOURequestStepAmount #92775git blameshows the previewcanApprove()/ animation action selection lines came from commit73665ddcb44, while the approve-flow metadata write came from021f04d8673. The local checkout is grafted/shallow, so fullgit show --statis noisy, but targeted line history confirms the current asymmetry.What changes do you think we should make in order to solve the problem?
Use the same pending-approve metadata pattern for the single report approval flow, but keep the change scoped so DEW-specific UI does not regress.
approveMoneyRequest(), enqueue the optimistic Onyx update before starting the animation.REPORT_METADATA[reportID].pendingExpenseAction = APPROVEfor all policies, not only DEW.ReportPreviewActionUtils.canApprove(), suppressApprovewhenreportMetadata.pendingExpenseAction === APPROVE. Do not changehasPendingDEWApprove()globally, because other places use it for DEW-specific messages/next-step behavior.Small diff sketch:
This should not regress DEW because DEW already uses the same metadata value. It should not regress search because search already sets and clears the same metadata for normal approvals. It is scoped to preview approve eligibility, so existing DEW-only display logic that uses
hasPendingDEWApprove()keeps the same behavior.What alternative solutions did you explore? (Optional)
Only moving
onApproved?.()afterAPI.write()reduces the race, but it still leaves the preview dependent on report state updates only.Changing
hasPendingDEWApprove()to ignore the DEW flag would be broader than needed and could affect DEW-specific next-step/system-message logic. A local pending-approve guard in the preview action utility is safer.KJ21-ENG commentedon Jun 9, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-06-09 13:22:15 UTC.
Proposal
What is the root cause of that problem?
The workspace chat preview derives the button from the expense report's current policy and report state, but the preview approval path can submit the approve workflow with a different policy.
In
ApproveActionButtonand the approve branch ofPayActionButton, the component reads the expense report policy, but passespolicy: activePolicyintoapproveMoneyRequest(). The hold-menu submit path does the same.approveMoneyRequest()then uses thatpolicyto decide whether the report is a DEW report and whether to optimistically updatestateNum,statusNum, andmanagerID.So if the active workspace policy is not the same as the report's policy, especially when the active policy is DEW and the report being approved is a normal workspace report, the approve action takes the DEW optimistic path and does not update the report status/manager. Meanwhile
getReportPreviewAction()evaluates the real report policy, sees a normal submitted report that is still assigned to the current approver, and returnsAPPROVEagain as soon as the short approved animation stops. When the backend update finally arrives, the button disappears again.What changes do you think we should make in order to solve the problem?
Make approval workflow decisions use the expense report's own policy, not the currently active workspace policy.
Concretely:
ApproveActionButton, the approve branch inPayActionButton, and the held-expense submit path used by the preview), pass the expense report policy as the workflowpolicywhen callingapproveMoneyRequest().approveMoneyRequest(), useexpenseReportPolicyas the canonical workflow policy for DEW detection, optimistic next-step generation, duplicate checks, and hold approval data. Keep the separate billing restriction check onexpenseReportPolicy.pendingExpenseActionand wait for backend confirmation; normal reports should optimistically updatestateNum,statusNum, andmanagerID.NVP_ACTIVE_POLICY_IDpoints to a DEW policy, verifying that the normal optimistic report update is still applied andgetReportPreviewAction()does not returnAPPROVEagain after the animation flag clears.I would also mirror the predicted approval state into the parent
REPORT_PREVIEWaction'schildStateNum,childStatusNum, and, when forwarded,childManagerAccountID, matching the pay/reopen/retract patterns. That keeps the preview status display in sync, but the main flicker fix is using the report policy for the approve workflow.What alternative solutions did you explore? (Optional)
A local "just approved" latch in the preview can hide the flicker, but it only masks the stale action selection. It would still let
approveMoneyRequest()build optimistic data from the wrong policy and would need extra failure-clearing logic to avoid hiding a legitimate retry. Fixing the policy source addresses the state mismatch directly.melvin-bot commentedon Jun 9, 2026
Current assignee @FitseTLT is eligible for the External assigner, not assigning anyone new.
[-]Bug: Approve button flickers (disappears, reappears, disappears) when approving a report from workspace chat report preview[/-][+][$250] Bug: Approve button flickers (disappears, reappears, disappears) when approving a report from workspace chat report preview[/+]melvin-bot commentedon Jun 9, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022064334100606413565
github-actions commentedon Jun 9, 2026
lorretheboy commentedon Jun 9, 2026
Proposal
What is the root cause of that problem?
The visibility of the Approve button is driven by two independent state sources that are never synchronized, and
getReportPreviewActionevaluates them in sequence — the local animation flag first, then the Onyx report status:App/src/libs/ReportPreviewActionUtils.ts
Lines 224 to 246 in 1f59d37
When you tap Approve,
approveMoneyRequestfires the animation callback and then writes the optimistic Onyx update:App/src/libs/actions/IOU/ReportWorkflow.ts
Lines 752 to 754 in 1f59d37
onApprovedsetsisApprovedAnimationRunning = true(local React state), whileAPI.writeflips the report'sstateNum/statusNumto approved/submitted in Onyx — a broadcast that propagates in a later render than the localsetState. So the suppression of the button bounces between two sources:isApprovedAnimationRunningis true → returnsPAY(the animated button), so Approve is hidden;canApprovesees the approved report → returnsVIEW, so Approve is hidden.The animation flag is reset on a fixed animation timer, independent of Onyx, when the settlement animation finishes:
App/src/components/SettlementButton/AnimatedSettlementButton.tsx
Lines 53 to 59 in 1f59d37
App/src/hooks/usePaymentAnimations.ts
Lines 9 to 13 in 1f59d37
If that timer-driven reset lands in a render where the optimistic status hasn't yet propagated (or is momentarily overwritten by
successData),canApproveis still true → the Approve button reappears, then disappears again once Onyx settles. This is a race, hence "not consistently reproducible." On a DEW policy it can't reproduce becauseapproveMoneyRequestskips thestateNumupdate and instead setsreportMetadata.pendingExpenseAction, which makescanApproveshort-circuit deterministically viahasPendingDEWApprove— there is no racing second source.What changes do you think we should make in order to solve the problem?
Make the button suppression come from a single source of truth so there is no window where
canApproveis re-evaluated as true. Tie the lifetime ofisApprovedAnimationRunningto the Onyx report state instead of the fixed animation timer: keep it true until the report is actually observed as approved/submitted, so by the time the flag clears,canApprovealready returns false.Concretely,
onAnimationFinishshould not unconditionally reset the flag here:App/src/components/SettlementButton/AnimatedSettlementButton.tsx
Lines 53 to 59 in 1f59d37
Instead defer
stopAnimationuntil the optimistic approval has propagated (e.g. gate the reset onisReportApproved/!isProcessingReportfor the report), so the animation flag and the Onyx status hand off cleanly with no overlap gap.What alternative solutions did you explore? (Optional)
Mirror the DEW path for normal workspaces: have
canApprovealso return false while an optimistic approve is pending (a pending flag on the report/metadata, the same mechanism that already makes DEW immune):App/src/libs/ReportPreviewActionUtils.ts
Lines 80 to 92 in 1f59d37
This removes the dependency on
stateNumpropagation timing entirely, at the cost of touching the optimistic data inapproveMoneyRequest.Proposed change (for review): main...lorretheboy:App:proposal-93067
mukhrr commentedon Jun 9, 2026
updated proposal. RCA and solution remained unchanged
50 remaining items
melvin-bot commentedon Jul 5, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Jul 5, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon Jul 6, 2026
Payment Summary
Contributor: @KJ21-ENG paid $250 via Upwork
Contributor+: @FitseTLT due $250 via NewDot
@KJ21-ENG can you please accept the job below? Please reply here and tag me once you have.
https://www.upwork.com/jobs/~022064334100606413565
^ Test case created. Thx
KJ21-ENG commentedon Jul 6, 2026
@mallenexpensify offer accepted, Thanks!
mallenexpensify commentedon Jul 6, 2026
@KJ21-ENG paid, summary updated above. Thx.
flaviadefaria commentedon Jul 31, 2026
Approved: @FitseTLT due $250 via NewDot