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-02] [$250] Android - Category - "Default tax rate" briefly changes back to the default one #50078
Version Number: 9.0.43-1 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Issue reported by: Applause - Internal Team
We use categoryName from url params to get tax rate name. However, after changing catefory name, categoryName remains old value for a brief moment before it gets updated:
And policy?.rules?.expenseRules would have data of new category name, which will make categoryName doesn't exist in the rules, CategoryUtils.getCategoryDefaultTaxRate returns default rate value.
What changes do you think we should make in order to solve the problem?
We should use policyCategory?.name, as this value also gets updated simultaneously when changing category name.
Edited by proposal-police: This proposal was edited at 2024-10-16 16:07:27 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
"Default tax rate" briefly changes back to the default one
What is the root cause of that problem?
When we return to the category page from the edit category page, the function defaultTaxRateText is executed before categoryName is updated, so the function defaultTaxRateText still receives the old categoryName. However, since policy?.rules?.expenseRules has been updated, the logic inside the defaultTaxRateText function will return the defaultTaxRate. Because of this, we will see Tax displaying the old tax text that is defaultTaxRate.
The reason defaultTaxRateText is executed before categoryName is updated is that policy?.rules?.expenseRules was changed when we called RENAME_WORKSPACE_CATEGORY, and it is in the dependency of the useMemo hook of the function defaultTaxRateText.
After that, categoryName will update and set the new value in the URL parameters. Consequently, defaultTaxRateText will re-render again because categoryName changed in the dependencies of the useMemo hook, and defaultTaxRateText will update with the correct tax text.
Because defaultTaxRateText renders twice, the first time it receives the old category and returns the default tax text, and the second time it receives the new category name and returns the correct tax text. So, this issue happens, and it only happens once.
This video describes what I mentioned above.Screen.Recording.2024-10-24.at.19.03.25.mp4
This issue happened only once after the first editing of the category name due to changes in the policy?.rules?.expenseRules data object structure. In React, useEffect or useMemo use shallow comparison: React only compares references of objects/arrays, not their contents.
You can see in the JSON below that policy?.rules?.expenseRules changes after the first editing of the category name, and it will not change for the next edited category name because the policy?.rules?.expenseRules object structure does not change. Therefore, this issue will not happen with the next edited category name.
and policy?.rules?.expenseRules
This is policy?.rules?.expenseRules data
// Before editing the category name (from SetPolicyCategoryTax response)
[
{
"tax": { "field_id_TAX": { "externalID": "id_TAX_RATE_1" } },
"applyWhen": [
{ "condition": "matches", "field": "category", "value": "Taxes" }
]
}
]
// After editing the category name and going back to the category page(from RenameWorkspaceCategory response)
[
{
"applyWhen": [
{ "condition": "matches", "field": "category", "value": "Taxes" }
],
"id": "671a27db42e27",
"tax": { "field_id_TAX": { "externalID": "id_TAX_RATE_1" } }
}
]
What changes do you think we should make in order to solve the problem?
To resolve this issue, we must call defaultTaxRateText after the category name update is complete. To do that, we must delay going back until the category name has finished updating. Something like this:
What alternative solutions did you explore? (Optional)
alternative solutions 1
Or we can use the policyCategory data to get the new category name after editing to retrieve the default tax rate, because policyCategory has updated values that match with expenseRules
changed the title [-]Android - Category - "Default tax rate" briefly changes back to the default one[/-][+][$250] Android - Category - "Default tax rate" briefly changes back to the default one[/+]on Oct 9, 2024
Activity
melvin-bot commentedon Oct 2, 2024
Triggered auto assignment to @JmillsExpensify (
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.daledah commentedon Oct 2, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
"Default tax rate" briefly changes back to the default one when changing category name for the first time
What is the root cause of that problem?
In
App/src/pages/workspace/categories/CategorySettingsPage.tsx
Lines 84 to 85 in 19a137d
We use
categoryNamefrom url params to get tax rate name. However, after changing catefory name,categoryNameremains old value for a brief moment before it gets updated:App/src/pages/workspace/categories/CategorySettingsPage.tsx
Lines 62 to 67 in 19a137d
And
policy?.rules?.expenseRuleswould have data of new category name, which will makecategoryNamedoesn't exist in the rules,CategoryUtils.getCategoryDefaultTaxRatereturns default rate value.What changes do you think we should make in order to solve the problem?
We should use
policyCategory?.name, as this value also gets updated simultaneously when changing category name.App/src/pages/workspace/categories/CategorySettingsPage.tsx
Line 85 in 19a137d
What alternative solutions did you explore? (Optional)
NA
huult commentedon Oct 3, 2024
Edited by proposal-police: This proposal was edited at 2024-10-16 16:07:27 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
"Default tax rate" briefly changes back to the default one
What is the root cause of that problem?
When we return to the category page from the edit category page, the function
defaultTaxRateTextis executed beforecategoryNameis updated, so the functiondefaultTaxRateTextstill receives theold categoryName. However, sincepolicy?.rules?.expenseRuleshas been updated, the logic inside thedefaultTaxRateTextfunction will return thedefaultTaxRate. Because of this, we will see Tax displaying the old tax text that isdefaultTaxRate.The reason
defaultTaxRateTextis executed beforecategoryNameis updated is thatpolicy?.rules?.expenseRuleswas changed when we calledRENAME_WORKSPACE_CATEGORY, and it is in the dependency of theuseMemohook of the functiondefaultTaxRateText.App/src/pages/workspace/categories/CategorySettingsPage.tsx
Line 98 in 19a137d
After that,
categoryNamewill update and set the new value in the URL parameters. Consequently,defaultTaxRateTextwill re-render again becausecategoryNamechanged in the dependencies of theuseMemohook, anddefaultTaxRateTextwill update with the correct tax text.App/src/pages/workspace/categories/CategorySettingsPage.tsx
Line 66 in 19a137d
Because
defaultTaxRateTextrenders twice, the first time it receives the old category and returns the default tax text, and the second time it receives the new category name and returns the correct tax text. So, this issue happens, and it only happens once.This video describes what I mentioned above.
Screen.Recording.2024-10-24.at.19.03.25.mp4
This issue happened only once after the first editing of the category name due to changes in the policy?.rules?.expenseRules data object structure. In React, useEffect or useMemo use shallow comparison: React only compares references of objects/arrays, not their contents.
You can see in the JSON below that policy?.rules?.expenseRules changes after the first editing of the category name, and it will not change for the next edited category name because the policy?.rules?.expenseRules object structure does not change. Therefore, this issue will not happen with the next edited category name.
and
policy?.rules?.expenseRulesThis is
policy?.rules?.expenseRulesdataWhat changes do you think we should make in order to solve the problem?
To resolve this issue, we must call defaultTaxRateText after the category name update is complete. To do that, we must delay going back until the category name has finished updating. Something like this:
// .src/pages/workspace/categories/EditCategoryPage.tsx#L52 const editCategory = useCallback( (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => { .... + InteractionManager.runAfterInteractions(() => { + requestAnimationFrame(() => { Navigation.goBack( isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), ); + }); + }); }, [backTo, currentCategoryName, route.params.categoryName, route.params.policyID], );What alternative solutions did you explore? (Optional)
alternative solutions 1
Or we can use the policyCategory data to get the new category name after editing to retrieve the default tax rate, because policyCategory has updated values that match with expenseRules
Details
POCScreen.Recording.2024-10-03.at.23.19.38.mov
melvin-bot commentedon Oct 7, 2024
@JmillsExpensify Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Oct 9, 2024
@JmillsExpensify 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
melvin-bot commentedon Oct 9, 2024
Job added to Upwork: https://www.upwork.com/jobs/~021844119049804579315
[-]Android - Category - "Default tax rate" briefly changes back to the default one[/-][+][$250] Android - Category - "Default tax rate" briefly changes back to the default one[/+]melvin-bot commentedon Oct 9, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (
External)87 remaining items
allgandalf commentedon Dec 30, 2024
Checklist ✅ , Pending Payment 💵
melvin-bot commentedon Jan 6, 2025
@JmillsExpensify, @arosiclair, @wildan-m, @allgandalf Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
melvin-bot commentedon Jan 7, 2025
@JmillsExpensify, @arosiclair, @wildan-m, @allgandalf Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Jan 8, 2025
@JmillsExpensify, @arosiclair, @wildan-m, @allgandalf Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Jan 10, 2025
@JmillsExpensify, @arosiclair, @wildan-m, @allgandalf Still overdue 6 days?! Let's take care of this!
melvin-bot commentedon Jan 13, 2025
@JmillsExpensify, @arosiclair, @wildan-m, @allgandalf 10 days overdue. I'm getting more depressed than Marvin.
JmillsExpensify commentedon Jan 13, 2025
Apologies for the delay ya'll. Let me post the payment summary and get this one settled.
Payment summary:
JmillsExpensify commentedon Jan 13, 2025
All contributors paid via Upwork, and regression test created. I'm closing this out!