Skip to content

Add isLoading guard to onboarding pages to prevent duplicate tasks#89991

Draft
MelvinBot wants to merge 6 commits into
mainfrom
claude-onboardingDuplicateTaskGuard
Draft

Add isLoading guard to onboarding pages to prevent duplicate tasks#89991
MelvinBot wants to merge 6 commits into
mainfrom
claude-onboardingDuplicateTaskGuard

Conversation

@MelvinBot
Copy link
Copy Markdown
Contributor

Explanation of Change

During onboarding, clicking "Continue" multiple times (after FormProvider's 1-second debounce window) fires completeOnboarding repeatedly, and each call generates fresh optimistic task IDs via prepareOnboardingOnyxData — producing duplicate tasks in Concierge.

This adds an isLoading state guard to the three onboarding pages that call completeOnboarding without one:

  • BaseOnboardingPersonalDetails — adds isLoading state and passes it to FormProvider
  • BaseOnboardingPurpose — adds isLoading state to guard the onPress handlers
  • BaseOnboardingWorkspaceOptional — adds isLoading state to guard both completeOnboarding and createWorkspaceAndCompleteOnboarding, and passes it to the Skip and Create Workspace buttons

This matches the existing pattern in BaseOnboardingInterestedFeatures, which already has this guard.

Fixed Issues

$ #89904
PROPOSAL: #89904 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.

  • Verify that no errors appear in the JS console

Offline tests

// TODO: The human co-author must fill out the offline tests before marking this PR as "ready for review"

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
AI Tests
  • lint-changed: passed
  • typecheck-tsgo: passed (pre-existing errors in unrelated files only)
  • onboarding tests (12 suites, 147 tests): all passed

…ation

When clicking Continue multiple times during onboarding, each click
fires completeOnboarding with fresh optimistic task IDs, creating
duplicate tasks in Concierge. Add isLoading state to
BaseOnboardingPersonalDetails, BaseOnboardingPurpose, and
BaseOnboardingWorkspaceOptional, matching the existing pattern in
BaseOnboardingInterestedFeatures.

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...gPersonalDetails/BaseOnboardingPersonalDetails.tsx 89.58% <42.85%> (-2.73%) ⬇️
.../pages/OnboardingPurpose/BaseOnboardingPurpose.tsx 87.67% <33.33%> (-3.51%) ⬇️
...kspaceOptional/BaseOnboardingWorkspaceOptional.tsx 0.00% <0.00%> (ø)
... and 13 files with indirect coverage changes

@linhvovan29546
Copy link
Copy Markdown
Contributor

@MelvinBot Please recheck this change to ensure it matches BaseOnboardingInterestedFeatures. In BaseOnboardingInterestedFeatures, we added async/await for completeOnboarding. And reset loading after complete onboarding

@linhvovan29546
Copy link
Copy Markdown
Contributor

@MelvinBot Also please resolve conflict

Match the pattern from BaseOnboardingInterestedFeatures:
- Make completeOnboarding calls async with await
- Add try/catch/finally to reset isLoading after completion
- Add Log.warn for error cases

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Updated all three files to match the BaseOnboardingInterestedFeatures pattern:

  • async/await for completeOnboarding / completeOnboardingReport calls
  • try/catch/finally with setIsLoading(false) in the finally block to reset loading state
  • Log.warn in catch blocks for error visibility

Changes per file:

  • BaseOnboardingPersonalDetails: local completeOnboarding is now async with await completeOnboardingReport(...) + try/catch/finally
  • BaseOnboardingPurpose: onPress handler is now async with await completeOnboarding(...) + try/catch/finally
  • BaseOnboardingWorkspaceOptional: both completeOnboarding and createWorkspaceAndCompleteOnboarding are now async with await + try/catch/finally

…icateTaskGuard

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>

# Conflicts:
#	src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
#	src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx
#	src/pages/OnboardingWorkspaceOptional/BaseOnboardingWorkspaceOptional.tsx
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Resolved merge conflicts with main. The conflicts were in all three onboarding files where main replaced CONST.ONBOARDING_CHOICES.PERSONAL_SPEND checks with isTrackOnboardingChoice() and updated the engagementChoice variable in createWorkspaceAndCompleteOnboarding. Both sets of changes are now combined.

Replace try/catch/finally with try/catch, placing setIsLoading(false)
in both the success path and catch block. React Compiler cannot handle
TryStatement with a finalizer clause.

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Fixed the failing React Compiler Compliance check: replaced try/catch/finally with try/catch (duplicating setIsLoading(false) in both the success path and catch block) in all three onboarding files. React Compiler cannot handle TryStatement with a finally clause.

@linhvovan29546
Copy link
Copy Markdown
Contributor

@MelvinBot Resolve conflict and mark PR as "Ready for review"

Resolve conflicts: keep async/await + try/catch pattern from PR,
adopt main's removal of betas parameter from onboarding calls.

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot MelvinBot marked this pull request as ready for review May 21, 2026 07:37
@MelvinBot MelvinBot requested a review from a team as a code owner May 21, 2026 07:37
@melvin-bot melvin-bot Bot requested review from heyjennahay and linhvovan29546 and removed request for a team May 21, 2026 07:37
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 21, 2026

@linhvovan29546 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@MelvinBot
Copy link
Copy Markdown
Contributor Author

Resolved merge conflicts and marked as ready for review.

Conflicts resolved in 3 files — kept the async/await + try/catch pattern from this PR, adopted main's removal of the betas parameter from onboarding calls:

  • BaseOnboardingPersonalDetails.tsx
  • BaseOnboardingPurpose.tsx
  • BaseOnboardingWorkspaceOptional.tsx

@MelvinBot
Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR.

Next steps: A human should review the recent commits and resolve the conflicting CI errors manually.

Copy link
Copy Markdown

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

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: ddef3b135b

ℹ️ 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".

return;
}

setIsLoading(true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear loading state when purpose is unset before submit

handleSubmit now sets isLoading to true before calling completeOnboarding, but completeOnboarding immediately returns when onboardingPurposeSelected is falsy. In that state (which can happen if the page is reached via direct navigation/rehydration without a selected purpose), the loading flag is never reset, so the form stays stuck in loading and Continue cannot be pressed again without a reload.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MelvinBot Please address this. I think we can move setIsLoading to completeOnboarding.

Copy link
Copy Markdown
Contributor Author

@MelvinBot MelvinBot May 21, 2026

Choose a reason for hiding this comment

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

Done — moved setIsLoading(true) into the completeOnboarding callback (after the guards), matching the existing pattern in BaseOnboardingWorkspaceOptional. Also added isLoading to the guard and dependency array. The track onboarding path in handleSubmit keeps its own setIsLoading(true) since it does not go through this callback.

Moves setIsLoading(true) from handleSubmit into the completeOnboarding
useCallback, after the guard checks. This prevents isLoading from being
set when completeOnboarding returns early (e.g. when
onboardingPurposeSelected is falsy), which would leave the form stuck
in a loading state.

Matches the existing pattern in BaseOnboardingWorkspaceOptional.

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner May 21, 2026 08:05
@melvin-bot melvin-bot Bot requested a review from Gonals May 21, 2026 08:05
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 21, 2026

@Gonals Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot removed the request for review from a team May 21, 2026 08:05
@Gonals Gonals marked this pull request as draft May 21, 2026 10:14
@Gonals
Copy link
Copy Markdown
Contributor

Gonals commented May 21, 2026

Setting this as a draft until ready for review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants