fix(onboarding): make Submit onboarding hook async with try/catch/finally error handling#92020
Draft
mountiny wants to merge 2 commits into
Draft
fix(onboarding): make Submit onboarding hook async with try/catch/finally error handling#92020mountiny wants to merge 2 commits into
mountiny wants to merge 2 commits into
Conversation
The autoCreateSubmitWorkspace callback fired completeOnboarding as fire-and-forget with no error handling. If the API call rejected, the user was silently stuck; navigation and Onyx cleanup never ran. Make the callback async and wrap completeOnboarding in try/catch/finally matching the pattern already used by useAutoCreateTrackWorkspace, so navigation and state cleanup always execute regardless of API outcome. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the EMPLOYER/Submit onboarding auto-workspace creation flow by awaiting completeOnboarding() and ensuring cleanup + navigation always runs, even when the API call fails.
Changes:
- Make
useAutoCreateSubmitWorkspace’s callbackasyncand wrapcompleteOnboarding()intry/catch/finally, logging failures viaLog.warn. - Move Onyx cleanup (
setOnboardingAdminsChatReportID,setOnboardingPolicyID) and post-onboarding navigation intofinallyso the user always exits onboarding. - Update and extend unit tests to await the hook and cover the rejection path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/hooks/useAutoCreateSubmitWorkspace.ts |
Await onboarding completion with try/catch/finally, log failures, and always clear onboarding state + navigate. |
tests/unit/hooks/useAutoCreateSubmitWorkspace.test.ts |
Await the async hook in relevant tests and add coverage for completeOnboarding rejection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…piler React Compiler cannot lower TryStatement with a finally clause inside useCallback. Move setOnboarding*() and navigate() after the try/catch block instead — they always execute regardless of whether the try body or catch body ran, achieving the same semantics as finally. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation of Change
autoCreateSubmitWorkspacewas callingcompleteOnboardingas fire-and-forget with no error handling. If the API call rejected (e.g. server error, network timeout), the user was silently stuck: navigation and Onyx cleanup code ran synchronously before the await, meaning the user landed on a broken state with stale onboarding keys still set.Make the callback
asyncand wrapcompleteOnboardingintry/catch/finally, matching the pattern already used byuseAutoCreateTrackWorkspace:try: awaitscompleteOnboarding— the API call now blocks navigationcatch: logs a warning viaLog.warn— same asuseAutoCreateTrackWorkspacefinally: always runssetOnboardingAdminsChatReportID(),setOnboardingPolicyID(), andnavigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue()— user always exits the onboarding screen regardless of API outcomeNo
shouldWaitForRHPVariantInitializationis needed — Submit doesn't consume the RHP variant from the response, and bothcreateWorkspaceandcompleteOnboardinguseAPI.write()(same persisted sequential queue), so ordering is already guaranteed.Fixed Issues
$ https://github.com/Expensify/Expensify/issues/389503
Tests
completeOnboardingto reject, verify you still navigate to the workspace and are not stuck on the onboarding screenOffline tests
N/A —
completeOnboardingalready usesAPI.write()which handles offline via the persisted queue; this change does not alter offline behaviour.QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
N/A — no UI changes
Android: mWeb Chrome
N/A — no UI changes
iOS: Native
N/A — no UI changes
iOS: mWeb Safari
N/A — no UI changes
MacOS: Chrome / Safari
N/A — no UI changes