Fix tax updating for changing waypoints or currency#73045
Conversation
| if (defaultTaxCode !== currentTaxCode) { | ||
| setMoneyRequestTaxRate(transactionID, defaultTaxCode ?? ''); | ||
| } | ||
| }, [customUnitRateID, policy, shouldShowTax, transaction, transactionID]); |
There was a problem hiding this comment.
❌ PERF-6 (docs)
Instead of passing entire objects as dependencies, specify individual object properties to create more granular dependency tracking and reduce unnecessary hook executions.
}, [customUnitRateID, policy, shouldShowTax, transaction?.taxCode, transaction?.currency, transaction?.modifiedCurrency, transactionID]);There was a problem hiding this comment.
This suggestion is not correct as written. In theory I agree with the principle, but in practice there are a bunch of transaction fields used within this effect, and while I could enumerate them all, it would make the effect more brittle - changing one of the TransactionUtils functions to use an additional property would result in the effect not being re-run when it needs to.
This is the kind of thing React Compiler could probably memoize much more effectively than we could manually, because it could deeply analyze the usage of all variables in your function scope and apply the kind of granular memoization that this comment strives for, but can do it reliably at build time.
| previousTaxCode, | ||
| distance, | ||
| ]); | ||
| }, [policy, shouldShowTax, transaction, isDistanceRequest, customUnitRateID, distance]); |
There was a problem hiding this comment.
❌ PERF-6 (docs)
Instead of passing entire objects as dependencies, specify individual object properties to create more granular dependency tracking and reduce unnecessary hook executions.
}, [policy, shouldShowTax, transaction?.amount, transaction?.taxAmount, transaction?.taxCode, transaction?.currency, transaction?.transactionID, isDistanceRequest, customUnitRateID, distance]);
Codecov Report❌ Patch coverage is
... and 9 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@roryabraham there is a regression with these changes. taxcodeissuechanges.mp4 |
|
@Burhan-Rashid I'm not able to reproduce that regression on this branch. It is explicitly covered by the test/QA steps and the video I included in the PR description shows that the bug you describe is not present. |
|
LGTM |
I think there might have been some cache related issue on my local. I am also not able to reproduce it currently. Sorry for the inconvenience. |
|
No worries - thank you for your diligence in testing 😄 |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppandroid-app-2025-10-22_16.30.53.mp4Android: mWeb Chromeandroid-chrome-2025-10-22_16.25.46.mp4iOS: HybridAppios-app-2025-10-22_18.22.24.mp4iOS: mWeb Safariios-safari-2025-10-22_18.26.17.mp4MacOS: Chrome / Safaridesktop-chrome-2025-10-22_14.35.50.mp4MacOS: Desktopdesktop-app-2025-10-22_15.12.18.mp4 |
jjcoffee
left a comment
There was a problem hiding this comment.
LGTM! Tests well and is much cleaner like this, thanks for stepping in!
|
@luacmartins 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] |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 9.2.37-1 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.2.37-8 🚀
|
Explanation of Change
Due to excessive and incorrect value-diffing with
usePrevious, tax rates are not being correctly updated when parameters (such as the waypoints for a distance expense) change.Fixed Issues
$ #72380
Tests / QA Steps
Prerequisites
Create a workspace
Enable tax and distance rates
Set up two tax rates:
Go to workspace settings -> distance rates -> settings -> enable tax tracking
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