Skip to content

Show empty tax rate column when tax is deleted instead of default#87672

Closed
MelvinBot wants to merge 11 commits intomainfrom
claude-fixTaxRateDefaultAfterDeletion
Closed

Show empty tax rate column when tax is deleted instead of default#87672
MelvinBot wants to merge 11 commits intomainfrom
claude-fixTaxRateDefaultAfterDeletion

Conversation

@MelvinBot
Copy link
Copy Markdown
Contributor

Explanation of Change

When tax is deleted from an expense via "Delete tax" (introduced in #84769), taxCode is set to ''. However, getTaxName() used the || operator to fall back to the default tax code when taxCode was falsy, so '' || defaultTaxCode evaluated to the workspace's default tax code. This caused the tax rate column to display the default rate instead of being empty.

This PR adds an early return in getTaxName() when taxCode is explicitly '', and switches the remaining fallback from || to ?? so that only null/undefined trigger the default — not an intentionally cleared empty string.

Fixed Issues

$ #87667
PROPOSAL: #87667 (comment)

Tests

  1. Enable Taxes in a workspace
  2. Create two expenses with 5% tax rates in that workspace's chat
  3. Go to workspace settings > More features > Disable Taxes
  4. Open the expense report
  5. Open any expense, click Tax field, click "Delete tax"
  6. Close the expense detail
  7. Verify the tax rate column is empty (not showing the default tax rate)
  • Verify that no errors appear in the JS console

Offline tests

N/A - this is a display-only fix for how an already-saved transaction field is rendered.

QA Steps

Same as Tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
Checks run
Check Result
Prettier Pass
ESLint Pass
TypeScript (tsgo) Pass
Unit tests (TransactionUtils, MergeTransactionUtils) Pass (255/255)

Screenshots/Videos

Android: Native

N/A - logic-only change

Android: mWeb Chrome

N/A - logic-only change

iOS: Native

N/A - logic-only change

iOS: mWeb Safari

N/A - logic-only change

MacOS: Chrome / Safari

N/A - logic-only change

When tax is deleted via "Delete tax", taxCode is set to ''. Previously,
getTaxName used || which treated '' as falsy and fell back to the default
tax code, causing the tax rate column to show the default rate instead of
being empty.

Co-authored-by: Rory Abraham <roryabraham@users.noreply.github.com>
@roryabraham
Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@github-actions
Copy link
Copy Markdown
Contributor

🚧 @roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@roryabraham
Copy link
Copy Markdown
Contributor

roryabraham commented Apr 13, 2026

@youssef-lr reassigning to you in case you want to keep pushing this potential fix to this issue assigned to you: #87667

@youssef-lr youssef-lr requested a review from hoangzinh April 13, 2026 20:07
Comment thread src/libs/TransactionUtils/index.ts Outdated
function getTaxName(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>, shouldFallbackToValue = false) {
const defaultTaxCode = getDefaultTaxCode(policy, transaction);
// An empty string taxCode means tax was explicitly cleared (e.g. via "Delete tax"), so return undefined
if (transaction?.taxCode === '') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Is there any other situation in which a transaction can have an empty tax code?

Copy link
Copy Markdown
Contributor Author

@MelvinBot MelvinBot Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! You're right — the UpdateMoneyRequestTaxRate API response returns taxCode as null, not ''. My previous fix only handled the optimistic empty string case.

I've updated the check to handle both:

if (transaction?.taxCode === '' || transaction?.taxCode === null) {
    return undefined;
}

This covers:

  • '' — optimistic update when user deletes tax
  • null — API response after tax deletion
  • undefined — pre-tax expense (falls through to default tax code via ??)

Added a test case for the null scenario as well. All 183 tests pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — Onyx uses shouldRemoveNestedNulls: true during merge, so a null taxCode from the API becomes undefined after Onyx processes it, not null. The null check was dead code.

Removed the null check and the corresponding test. Only the empty string check remains for the optimistic update case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot it won't solve the original issue. Same feeback here #87672 (comment)

I guess you need to step back and find another solution

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — the successData approach only works for the immediate API response but won't survive page reload, reconnection, or Pusher updates, because the server stores taxCode as null and Onyx strips it to undefined every time.

New approach: removed the defaultTaxCode fallback in getTaxName() entirely. Expense creation already sets taxCode to the default explicitly (MoneyRequest.ts:217), so a missing taxCode reliably means tax was deleted or never existed. No need to distinguish the two — both should show empty.

Also reverted the successData taxCode/taxValue preservation since it's no longer needed.

@MelvinBot
Copy link
Copy Markdown
Contributor Author

Yes, there are several other situations where a transaction can have an empty taxCode:

  1. Tax Rate Page editing (IOURequestStepTaxRatePage.tsx:85) — when a user edits an expense and clears the tax via the tax rate selection page, taxCode is set to ''.

  2. TaxPicker deselection (TaxPicker.tsx:131,145) — when a user deselects a tax option (e.g., re-clicks the currently selected tax, or the previously selected tax rate no longer exists/has changed in the policy).

  3. Transaction creation defaults — many transaction creation functions (buildOptimisticTransaction, splitBill, trackExpenseWithReceipt, etc.) destructure taxCode = '' as a default, so any transaction created without an explicit tax code starts with an empty string.

  4. TaxController default (TaxController.tsx:43-46) — if the workspace has no defaultTaxCode, the tax code will be set to empty.

All of these paths would benefit from the getTaxName() fix in this PR, since they all result in taxCode === '' and would previously have fallen through to the default tax rate display.

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot, your solution doesn't work because UpdateMoneyRequestTaxRate API will return taxAmount, taxCode, and taxValue as null.

@MelvinBot
Copy link
Copy Markdown
Contributor Author

Good catch — you're right. The optimistic update sets taxCode: '', but after the UpdateMoneyRequestTaxRate API responds, the server returns taxCode: null, which overwrites the empty string via Onyx merge. At that point, the taxCode === '' check on line 2152 no longer matches, and line 2157's ?? defaultTaxCode fallback kicks in, showing the default rate again.

The fix needs to also handle null (explicit server value, distinct from undefined = "never set"). I'll wait for direction from the assignee youssef-lr on whether to update this PR accordingly.

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot, please note that when Onyx stores that null data, it will clear that data

@MelvinBot
Copy link
Copy Markdown
Contributor Author

Thanks for the correction. So when the API returns taxCode: null and Onyx merges it, Onyx removes the taxCode key entirely — meaning transaction.taxCode becomes undefined, not null. That makes the problem harder: after the merge, there's no way to distinguish "tax was explicitly cleared" (undefined via Onyx null-removal) from "tax was never set" (undefined because the field doesn't exist).

The ?? fallback treats both as "use default," which is correct for "never set" but wrong for "explicitly cleared." A possible approach would be to use a sentinel value (e.g., NONE or a dedicated constant) instead of '' for the optimistic update, so it survives the Onyx merge — but that requires changes to both the client and potentially the API contract.

I'll defer to the assignee on the right approach here.

@hoangzinh
Copy link
Copy Markdown
Contributor

@youssef-lr can you assign this issue for me so I can work with MelvinBot in this PR?

@youssef-lr
Copy link
Copy Markdown
Contributor

You are assigned @hoangzinh

@hoangzinh
Copy link
Copy Markdown
Contributor

You are assigned @hoangzinh

yeah, but I'm assigned as a reviewer, not an assignee. Hence, Melvin can't implement this PR for me #87672 (comment)

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot can you apply above suggestion please?

When tax is deleted, the API returns taxCode as null. Onyx removes null
values during merge, leaving taxCode as undefined. The previous check
only handled taxCode === '' (optimistic), missing the post-API state.
Broadened the check to handle all falsy taxCode values.

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Applied the fix. The getTaxName check is now broadened from taxCode === '' to !transaction?.taxCode, which handles all three states after tax deletion:

  • '' (optimistic update)
  • null (API response)
  • undefined (after Onyx clears the null)

All 255 unit tests (TransactionUtils + MergeTransactionUtils) pass, along with TypeScript and ESLint checks.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/TransactionUtils/index.ts 84.28% <100.00%> (+0.90%) ⬆️
src/libs/actions/IOU/UpdateMoneyRequest.ts 60.61% <100.00%> (ø)
... and 108 files with indirect coverage changes

@MelvinBot
Copy link
Copy Markdown
Contributor Author

The failing perf-tests check is unrelated to this PR's changes. The error is a render count regression in SidebarLinks ("Render count difference exceeded the allowed deviation of 0. Current difference: 1"), but this PR only modifies getTaxName() in TransactionUtils/index.ts — it doesn't touch any sidebar or rendering logic.

This appears to be a flaky perf test — other PRs (e.g. knip-audit-export-6) also failed the same check recently. Please re-run the failed job to get a clean pass.

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot Please merge the latest main branch into this branch.

…ultAfterDeletion

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Merged the latest main branch into this PR branch.

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot makes this PR ready for review

@MelvinBot MelvinBot marked this pull request as ready for review April 22, 2026 13:01
@MelvinBot MelvinBot requested a review from a team as a code owner April 22, 2026 13:01
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Done! This PR has been marked as ready for review. 🚀

@melvin-bot melvin-bot Bot requested review from a team, flaviadefaria and hoangzinh and removed request for a team April 22, 2026 13:02
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Apr 22, 2026

@hoangzinh 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]

@melvin-bot melvin-bot Bot removed the request for review from a team April 22, 2026 13:02
@hoangzinh
Copy link
Copy Markdown
Contributor

hoangzinh commented Apr 22, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-04-22.at.20.22.02.mov

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot current implementation would cause the same deploy blocker here #85729

The previous guard `!transaction?.taxCode` treated both '' (explicitly
deleted) and undefined (never set, e.g. expense created before taxes
enabled) the same way — skipping the default tax fallback. This would
re-introduce the deploy blocker from #85729 where
pre-tax expenses show an empty tax field instead of the default rate.

Changed to `transaction?.taxCode === ''` so only explicitly deleted
tax codes skip the fallback. Added a regression test for the
undefined-taxCode scenario.

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner April 22, 2026 14:25
@melvin-bot melvin-bot Bot requested a review from youssef-lr April 22, 2026 14:25
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Apr 22, 2026

@youssef-lr 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]

@melvin-bot melvin-bot Bot removed the request for review from a team April 22, 2026 14:25
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Good catch! You're right — the !transaction?.taxCode guard treated both '' (explicitly deleted via "Delete tax") and undefined (never set, e.g. expense created before taxes were enabled) the same way, skipping the default tax fallback. This would re-introduce the exact scenario from #85729.

Fix pushed: Changed the guard from !transaction?.taxCode to transaction?.taxCode === '' so only explicitly deleted tax codes skip the fallback. Expenses with undefined taxCode (pre-tax expenses) will still correctly fall back to the default tax rate via getDefaultTaxCode(). Also added a regression test for the undefined-taxCode scenario.

@MelvinBot
Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

MelvinBot has made 7 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR.

Next steps: A human should review the recent commits and resolve the conflicting CI errors manually.

@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot, then you won't fix the original issue, because when UpdateMoneyRequestTaxRate API response, it will return the "taxCode" as null

Screen.Recording.2026-04-22.at.22.05.52.mov

The UpdateMoneyRequestTaxRate API returns taxCode as null (not empty string)
after tax deletion. The previous fix only handled empty string. Now both
null and empty string are treated as explicitly cleared tax.

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
@hoangzinh
Copy link
Copy Markdown
Contributor

@MelvinBot as I mentioned here, when Onyx stores that null data, it will clear that data #87672 (comment)

MelvinBot and others added 2 commits April 23, 2026 07:39
Onyx removes null values during merge (shouldRemoveNestedNulls),
so taxCode will be undefined (not null) after the API response.
Only the empty string check is needed for the optimistic update.

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
The API returns taxCode: null after tax deletion, and Onyx strips null
values during merge (shouldRemoveNestedNulls), making taxCode undefined.
This is indistinguishable from a pre-tax expense that never had taxCode.

Fix: include the optimistic taxCode/taxValue in successData so they
persist through the API response merge. This ensures taxCode stays as
'' (deleted) rather than becoming undefined (default fallback).

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

You're right — the getTaxName guard alone doesn't survive the API response. Here's what happens:

  1. Optimistic: taxCode = '' → guard catches it ✓
  2. API responds with taxCode: null → Onyx strips null → taxCode becomes undefined → falls through to default ✗

I've added a fix at the data layer: the successData in getUpdateMoneyRequestParams now explicitly preserves taxCode and taxValue from the optimistic update when those fields were part of the transactionChanges. This ensures taxCode stays as '' (deleted) even after Onyx merges the API response, rather than becoming undefined (which would fall back to the default tax rate).

The getTaxName guard for '' remains needed to handle the preserved empty string.

Instead of trying to preserve taxCode='' through API round-trips
(which fails because Onyx strips null values from the server response),
remove the fallback to defaultTaxCode entirely in getTaxName().

Expense creation already sets taxCode to the default explicitly
(MoneyRequest.ts:217), so a missing taxCode reliably means tax was
deleted or never existed — showing empty is correct in both cases.

This also reverts the successData taxCode/taxValue preservation in
UpdateMoneyRequest.ts, which is no longer needed.

Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
@hoangzinh
Copy link
Copy Markdown
Contributor

hoangzinh commented Apr 23, 2026

@MelvinBot, please close this PR. We will address the original bug in this new PR #88580

@MelvinBot MelvinBot closed this Apr 23, 2026
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Closed this PR as requested by hoangzinh. The original bug (#87667) will be addressed in #88580.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants