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
[HOLD for payment 2025-01-24] [$250] Distance- Waypoint is saved when distance editor RHP is refreshed and dismissed without saving #52413
Version Number: 9.0.60-0 Reproducible in staging?: Y Reproducible in production?: Y If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers):applausetester+kh011101s2@applause.expensifail.com Issue reported by: Applause - Internal Team
Action Performed:
Go to staging.new.expensify.com
Go to workspace chat
Submit a distance expense
Go to transaction thread
Click Distance
Add another waypoint
Refresh the page while distance editor RHP is open (close and reopen the app on Android and iOS)
Click outside the RHP to dismiss it
Click Distance
Expected Result:
The waypoint added in Step 6 will not appear because the new distance is not saved
Actual Result:
The waypoint added in Step 6 appears even when the new distance is not saved
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Android: Standalone
Android: HybridApp
Android: mWeb Chrome
iOS: Standalone
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop
Screenshots/Videos
Add any screenshot/video evidenceBug6662755_1731429445776.20241113_003143.1.mp4
But it is never called for the case of a reloading the page
so when it is opened after refresh we re-load the changed transaction to the backup so if we dismiss it will have the new waypoints
What changes do you think we should make in order to solve the problem?
We should update to only load backup transaction if the the transactionBackup is empty
we can use Onyx.connect and run the code inside the callback in createBackupTransaction
by updating createBackupTransaction
function createBackupTransaction(transaction: OnyxEntry<Transaction>, isDraft: boolean) {
if (!transaction) {
return;
}
// In Strict Mode, the backup logic useEffect is triggered twice on mount. The restore logic is delayed because we need to connect to the onyx first,
// so it's possible that the restore logic is executed after creating the backup for the 2nd time which will completely clear the backup.
// To avoid that, we need to cancel the pending connection.
Onyx.disconnect(connection);
const newTransaction = {
...transaction,
};
const conn = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transaction.transactionID}`,
callback: (transactionBackup) => {
Onyx.disconnect(conn);
if (transactionBackup) {
Onyx.set(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transactionBackup);
return;
}
// Use set so that it will always fully overwrite any backup transaction that could have existed before
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transaction.transactionID}`, newTransaction);
},
});
}
// If the user opens IOURequestStepDistance in offline mode and then goes online, re-open the report to fill in missing fields from the transaction backup
if(!transaction?.reportID){
return;
}
Report.openReport(transaction?.reportID);
};
After the reload is complete, create a backup transaction with data that has not been restored to the original transaction. This causes the issue where we still see the waypoint edited but not saved
What changes do you think we should make in order to solve the problem?
To resolve this issue, we need to check if the page is reloaded, then we don't need to create a new backup with the edited data. By the following steps:
1 Create a new Onyx to indicate whether the page is reloaded or not
4 Add condition to check create new back up or not.
// src/pages/iou/request/step/IOURequestStepDistance.tsx#L215
useEffect(() => {
if (isCreatingNewRequest) {
return () => {};
}
// On mount, create the backup transaction.
- TransactionEdit.createBackupTransaction(transaction);+ InteractionManager.runAfterInteractions(() => {+ requestAnimationFrame(() => {+ // On mount, create the backup transaction.+ if (isTransactionPageRefreshing === true || isTransactionPageRefreshing === undefined) {+ if (transactionWasSaved.current) {+ TransactionEdit.removeBackupTransaction(transaction?.transactionID ?? '-1');+ return;+ }+ TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', IOUUtils.shouldUseTransactionDraft(action));+ if (!transaction?.reportID) {+ return;+ }+ Report.openReport(transaction?.reportID);+ return;+ }+ TransactionEdit.createBackupTransaction(transaction);+ });+ });
return () => {
// If the user cancels out of the modal without without saving changes, then the original transaction
// needs to be restored from the backup so that all changes are removed.
if (transactionWasSaved.current) {
TransactionEdit.removeBackupTransaction(transaction?.transactionID ?? '-1');
return;
}
TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', IOUUtils.shouldUseTransactionDraft(action));
// If the user opens IOURequestStepDistance in offline mode and then goes online, re-open the report to fill in missing fields from the transaction backup
if (!transaction?.reportID) {
return;
}
Report.openReport(transaction?.reportID);
};
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);
changed the title [-]Distance- Waypoint is saved when distance editor RHP is refreshed and dismissed without saving[/-][+][$250] Distance- Waypoint is saved when distance editor RHP is refreshed and dismissed without saving[/+]on Nov 14, 2024
@rayane-djouah@joekaufmanexpensify@rayane-djouah The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[@joekaufmanexpensify] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
1. Go to workspace chat
2. Submit a distance expense
3. Go to transaction thread
4. Click Distance
5. Add another waypoint
6. Refresh the page while distance editor RHP is open (close and reopen the app on Android and iOS)
7. Verify that the waypoint is restored to the original value and the unsaved waypoint change (the waypoint added in step (5) is reverted
Activity
melvin-bot commentedon Nov 12, 2024
Triggered auto assignment to @joekaufmanexpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.FitseTLT commentedon Nov 12, 2024
Edited by proposal-police: This proposal was edited at 2024-11-21 19:03:45 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Distance- Waypoint is saved when distance editor RHP is refreshed and dismissed without saving
What is the root cause of that problem?
We already have a code that is run on unmount to restore transaction here
App/src/pages/iou/request/step/IOURequestStepDistance.tsx
Line 230 in 8a83e2b
But it is never called for the case of a reloading the page
so when it is opened after refresh we re-load the changed transaction to the backup so if we dismiss it will have the new waypoints
App/src/pages/iou/request/step/IOURequestStepDistance.tsx
Line 221 in 8a83e2b
What changes do you think we should make in order to solve the problem?
We should update to only load backup transaction if the the transactionBackup is empty
we can use Onyx.connect and run the code inside the callback in createBackupTransaction
by updating createBackupTransaction
App/src/pages/iou/request/step/IOURequestStepDistance.tsx
Line 221 in 64eaf2f
Note that this will fix the bug not only on page reloadrefresh but also for app closing and reopening 👍
Or optionally
Or optionally
we need the setTimeout b/c by the time the effect is run useOnyx will not populate transactionBackup but
huult commentedon Nov 13, 2024
Edited by proposal-police: This proposal was edited at 2024-11-13 06:06:56 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Waypoint is saved when distance editor RHP is refreshed and dismissed without saving
What is the root cause of that problem?
When the page is reloaded, we can't execute this code to restore the original transaction from the backup.
App/src/pages/iou/request/step/IOURequestStepDistance.tsx
Lines 222 to 236 in 3897516
After the reload is complete, create a backup transaction with data that has not been restored to the original transaction. This causes the issue where we still see the waypoint edited but not saved
App/src/pages/iou/request/step/IOURequestStepDistance.tsx
Lines 214 to 220 in 3897516
What changes do you think we should make in order to solve the problem?
To resolve this issue, we need to check if the page is reloaded, then we don't need to create a new backup with the edited data. By the following steps:
1 Create a new Onyx to indicate whether the page is reloaded or not
// src/ONYXKEYS.ts#L459 + EDIT_DISTANCE_PAGE_RELOAD: 'editDistancePageReload_',2 Listen for the event before the reload
3 Add loading to wait value of edit distance reload
4 Add condition to check create new back up or not.
// src/pages/iou/request/step/IOURequestStepDistance.tsx#L215 useEffect(() => { if (isCreatingNewRequest) { return () => {}; } // On mount, create the backup transaction. - TransactionEdit.createBackupTransaction(transaction); + InteractionManager.runAfterInteractions(() => { + requestAnimationFrame(() => { + // On mount, create the backup transaction. + if (isTransactionPageRefreshing === true || isTransactionPageRefreshing === undefined) { + if (transactionWasSaved.current) { + TransactionEdit.removeBackupTransaction(transaction?.transactionID ?? '-1'); + return; + } + TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', IOUUtils.shouldUseTransactionDraft(action)); + if (!transaction?.reportID) { + return; + } + Report.openReport(transaction?.reportID); + return; + } + TransactionEdit.createBackupTransaction(transaction); + }); + }); return () => { // If the user cancels out of the modal without without saving changes, then the original transaction // needs to be restored from the backup so that all changes are removed. if (transactionWasSaved.current) { TransactionEdit.removeBackupTransaction(transaction?.transactionID ?? '-1'); return; } TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', IOUUtils.shouldUseTransactionDraft(action)); // If the user opens IOURequestStepDistance in offline mode and then goes online, re-open the report to fill in missing fields from the transaction backup if (!transaction?.reportID) { return; } Report.openReport(transaction?.reportID); }; // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []);POC
Screen.Recording.2024-11-13.at.12.57.58.mp4
Test Branch
What alternative solutions did you explore? (Optional)
joekaufmanexpensify commentedon Nov 14, 2024
Reproduced.
[-]Distance- Waypoint is saved when distance editor RHP is refreshed and dismissed without saving[/-][+][$250] Distance- Waypoint is saved when distance editor RHP is refreshed and dismissed without saving[/+]melvin-bot commentedon Nov 14, 2024
Job added to Upwork: https://www.upwork.com/jobs/~021857103747653162057
melvin-bot commentedon Nov 14, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @rayane-djouah (
External)81 remaining items
melvin-bot commentedon Jan 17, 2025
@rayane-djouah @joekaufmanexpensify @rayane-djouah The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
joekaufmanexpensify commentedon Jan 20, 2025
@rayane-djouah could you handle checklist here? TY!
joekaufmanexpensify commentedon Jan 22, 2025
Asked here
rayane-d commentedon Jan 22, 2025
BugZero Checklist:
Bug classification
Source of bug:
Where bug was reported:
Who reported the bug:
The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: https://github.com/Expensify/App/pull/26141/files#r1925694325
If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[@joekaufmanexpensify] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue: https://github.com/Expensify/Expensify/issues/464352
Regression Test Proposal
Do we agree 👍 or 👎
joekaufmanexpensify commentedon Jan 24, 2025
Added regression test issue above. All set to issue payment!
joekaufmanexpensify commentedon Jan 24, 2025
We need to pay:
joekaufmanexpensify commentedon Jan 24, 2025
@FitseTLT $250 sent and contract ended!
joekaufmanexpensify commentedon Jan 24, 2025
@rayane-djouah $250 sent and contract ended!
joekaufmanexpensify commentedon Jan 24, 2025
Upwork job closed.
joekaufmanexpensify commentedon Jan 24, 2025
All set, thanks everyone!