Fix addDelegate: stale closure, first-time user guard, and error handling#84594
Draft
Fix addDelegate: stale closure, first-time user guard, and error handling#84594
Conversation
… handling 1. Fix the early-return guard to allow first-time delegate users (where delegates is undefined) instead of silently aborting. 2. Remove delegates array from successData to prevent stale closure from overwriting server-provided data in the Onyx update pipeline. 3. Add errorFields to failureData so users see an error message when the backend returns a non-200 response. Co-authored-by: parasharrajat <parasharrajat@users.noreply.github.com>
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: Then you can close this PR and open a new one from your fork. |
7 tasks
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.
|
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
This PR fixes three issues in the
addDelegatefunction insrc/libs/actions/Delegate.tsthat contribute to the copilot invite succeeding at the API level but not persisting the delegate relationship on the frontend:Fix early-return guard for first-time delegate users: The guard
if (!delegatedAccess?.delegates)silently aborted whendelegateswasundefined, which happens for users who have never configured delegates. Changed to only abort whendelegatedAccessitself is missing, treatingundefineddelegates as an empty array.Fix stale closure overwriting server data in
successData: ThesuccessDelegateData()function rebuilt the entire delegates array from the closure-captured snapshot taken whenaddDelegate()was called. Since the Onyx update pipeline applies serveronyxDatafirst and then mergessuccessDataon top, this stale array could overwrite the authoritative delegate list returned by the server. Removed thedelegatesarray fromsuccessDataentirely so the server's response stands.Add error handling to
failureData: ThefailureDatadid not includeerrorFields.addDelegate[email], so when the backend returned a non-200 response, the delegate entry persisted withpendingAction: ADDbut no error was shown to the user. Added the error field so users see a proper error message on failure.Fixed Issues
$ #82446
PROPOSAL: #82446 (comment)
Tests
Offline tests
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 - Logic-only change, no UI modifications
Android: mWeb Chrome
N/A - Logic-only change, no UI modifications
iOS: Native
N/A - Logic-only change, no UI modifications
iOS: mWeb Safari
N/A - Logic-only change, no UI modifications
MacOS: Chrome / Safari
N/A - Logic-only change, no UI modifications