Conversation
|
@ahmedGaber93 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] |
|
LGTM |
| const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest, isPerDiemRequest); | ||
|
|
||
| // Update the tax code when the default changes (for example, because the transaction currency changed) | ||
| const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? ''; |
There was a problem hiding this comment.
❌ PERF-6 (docs)
The defaultTaxCode computation should be moved inside the useEffect or properly memoized to avoid running expensive operations on every render. Currently, getDefaultTaxCode(policy, transaction) is called on every render, which could include complex policy and transaction lookups.
// Option 1: Move computation inside useEffect
useEffect(() => {
if (!transactionID) {
return;
}
const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? '';
setMoneyRequestTaxRate(transactionID, defaultTaxCode);
}, [policy, transaction, transactionID]);
// Option 2: Properly memoize the computation
const defaultTaxCode = useMemo(() => getDefaultTaxCode(policy, transaction) ?? '', [policy, transaction]);| } | ||
| }, [customUnitRateID, policy, shouldShowTax, transaction, transactionID]); | ||
| setMoneyRequestTaxRate(transactionID, defaultTaxCode); | ||
| }, [defaultTaxCode, transactionID]); |
There was a problem hiding this comment.
❌ PERF-6 (docs)
The dependency array should specify individual object properties instead of entire objects. Currently, passing defaultTaxCode as a dependency means the effect will run whenever getDefaultTaxCode() returns a different reference, but we should be more specific about which properties actually matter.
// Instead of relying on defaultTaxCode computed outside, specify the actual dependencies:
useEffect(() => {
if (!transactionID) {
return;
}
const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? '';
setMoneyRequestTaxRate(transactionID, defaultTaxCode);
}, [policy?.taxRates, policy?.defaultExternalID, transaction?.currency, transaction?.amount, transactionID]);This creates more granular dependency tracking and reduces unnecessary hook executions when unrelated policy or transaction properties change.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
(cherry picked from commit 6dbd7cc) (cherry-picked to staging by blimpich)
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Cherry-picked to staging by https://github.com/blimpich in version: 9.2.37-4 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.2.37-8 🚀
|
|
🚀 Cherry-picked to staging by https://github.com/blimpich in version: 9.2.38-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.2.38-5 🚀
|
| const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? ''; | ||
| useEffect(() => { | ||
| // Set the default tax code when conditions change | ||
| if (!shouldShowTax || !transaction || !transactionID) { |
There was a problem hiding this comment.
We removed the shouldShowTax flag, which caused this issue #75056 (comment). In some cases we need to return early so we applied the fix in #76068.
Explanation of Change
Simpler is better! The problem in #73309 is that when the user changes their tax rate, the effect runs and we:
This fixes it by simplifying the effect to run only when the default changes, such as when the transaction currency changes. This way the user can still select a different tax rate if they choose to.
Fixed Issues
$ #73309
Tests
Prerequisites
Create a workspace
Enable tax and distance rates
Set up two tax rates:
Go to workspace settings -> distance rates -> settings -> enable tax tracking
Go to workspace settings -> distance rates -> choose a distance rate -> add a tax rate
Test changing tax rate manually
Test changing waypoints
Test changing currency
Offline tests
None.
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov
MacOS: Desktop