Skip to content

Remove useDeepCompareRef from MoneyRequestReportTransactionList#83432

Merged
mollfpr merged 6 commits intomainfrom
vit-removeDeepCompareRef-transactionList
Feb 27, 2026
Merged

Remove useDeepCompareRef from MoneyRequestReportTransactionList#83432
mollfpr merged 6 commits intomainfrom
vit-removeDeepCompareRef-transactionList

Conversation

@mountiny
Copy link
Contributor

@mountiny mountiny commented Feb 25, 2026

Explanation of Change

Removes the useDeepCompareRef anti-pattern from MoneyRequestReportTransactionList (1 of 3 call-sites tracked in the linked issue).

What changed:

  1. TransactionThreadNavigation.ts -- setActiveTransactionIDs is now idempotent. It tracks the last-written IDs in a module-level variable and skips the Onyx write when the content hasn't changed. clearActiveTransactionIDs resets this tracking. No Onyx.connect is needed because these two functions are the only writers to this key.

  2. MoneyRequestReportTransactionList.tsx -- The useDeepCompareRef wrapper and the intermediate join(',') workaround are both removed. The useEffect now uses visualOrderTransactionIDs directly as its dependency, with no eslint-disable comments. Referential re-fires are harmless because setActiveTransactionIDs guards against duplicate Onyx writes.

  3. Test file -- The helper hook mirrors the simplified component code. The "same content, new reference" test now verifies the effect does fire (since the reference changed), documenting that the idempotent guard lives in the action layer, not the component.

Why: useDeepCompareRef is marked as an anti-pattern in its own JSDoc. It runs deepEqual every render, violates exhaustive-deps conventions (risk of stale closures), and is incompatible with React Compiler optimizations. Moving the guard into the action layer is cleaner -- it benefits all callers, avoids eslint-disable comments, and uses idiomatic React patterns.

Fixed Issues

$ #83431

Tests

  1. Open a workspace with expense reports containing multiple transactions
  2. Navigate to the Search page and open a report with transactions (so SEARCH_REPORT route is focused)
  3. Verify transactions display correctly and prev/next navigation arrows work in the RHP
  4. Add or delete a transaction and verify the transaction list updates correctly
  5. Verify that no errors appear in the JS console
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline
  2. Open a report with transactions from Search
  3. Verify the transaction list still renders correctly
  4. Go back online and verify no duplicate or stale transaction IDs appear

QA Steps

  1. Open the app and navigate to Search
  2. Open any expense report that has multiple transactions
  3. Click on a transaction to open it in the RHP
  4. Use the prev/next arrows to navigate between transactions — verify the order matches the list
  5. Go back to the report, add a new expense, and verify it appears in the list
  6. Delete a transaction and verify it disappears from the list and prev/next navigation updates
  • 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.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Replace the useDeepCompareRef anti-pattern with a primitive
joined-string cache key for the visualOrderTransactionIDs effect.
The string key gives React a cheap equality check that prevents
the effect from re-firing when the array content is unchanged,
matching the previous behavior without deep comparison overhead
or React Compiler incompatibility.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mountiny mountiny requested review from a team as code owners February 25, 2026 09:52
@melvin-bot melvin-bot bot requested review from JmillsExpensify and huult and removed request for a team February 25, 2026 09:52
@melvin-bot
Copy link

melvin-bot bot commented Feb 25, 2026

@huult 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 February 25, 2026 09:52
clearActiveTransactionIDs();
};
}, [visualOrderTransactionIDsDeepCompare]);
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-5 (docs)

This eslint-disable suppresses react-hooks/exhaustive-deps but has no accompanying comment explaining why the rule is disabled. The intent here is that visualOrderTransactionIDsKey is used as a proxy for the visualOrderTransactionIDs array to avoid reference-based re-fires, but that reasoning should be documented inline.

Add a justification comment, for example:

// eslint-disable-next-line react-hooks/exhaustive-deps
// visualOrderTransactionIDsKey is a joined-string proxy for visualOrderTransactionIDs — the effect uses the array in its body but depends on the primitive key to avoid re-firing on referential changes
}, [visualOrderTransactionIDsKey]);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in ac0b517 — the join approach and all associated eslint-disable comments have been removed. The effect now uses visualOrderTransactionIDs directly, and the idempotent guard lives in setActiveTransactionIDs.

setActiveTransactionIDs(visualOrderTransactionIDs);
return () => {
clearActiveTransactionIDs();
};
Copy link
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-5 (docs)

This eslint-disable suppresses react-hooks/exhaustive-deps but has no accompanying comment explaining why the rule is disabled.

Add a justification comment, for example:

// eslint-disable-next-line react-hooks/exhaustive-deps
// visualOrderTransactionIDsKey is a joined-string proxy for visualOrderTransactionIDs — the effect uses the array in its body but depends on the primitive key to avoid re-firing on referential changes
}, [visualOrderTransactionIDsKey]);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in ac0b517 — the join approach and all associated eslint-disable comments have been removed. The effect now uses visualOrderTransactionIDs directly, and the idempotent guard lives in setActiveTransactionIDs.

@huult
Copy link
Contributor

huult commented Feb 25, 2026

I can review this PR if needed.

The react-compiler ESLint plugin is not configured in the test
environment, so disabling it causes a "Definition for rule not found"
error in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Contributor

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

Address CONSISTENCY-5 review feedback: explain why
react-hooks/exhaustive-deps is disabled on the useEffect
that uses visualOrderTransactionIDsKey as a primitive proxy.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mountiny
Copy link
Contributor Author

@huult that would be great, mainly testing for edge cases

@github-actions

This comment has been minimized.

Copy link
Contributor

@JmillsExpensify JmillsExpensify left a comment

Choose a reason for hiding this comment

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

No product review required.

Move the duplicate-write guard from the component layer into
setActiveTransactionIDs itself, using a local module variable
to track the last-written IDs. This eliminates the join(',')
workaround, eslint-disable comments, and benefits all callers.

Made-with: Cursor
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

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

Files with missing lines Coverage Δ
...stReportView/MoneyRequestReportTransactionList.tsx 1.32% <0.00%> (+0.02%) ⬆️
src/libs/actions/TransactionThreadNavigation.ts 11.11% <20.00%> (+11.11%) ⬆️
... and 263 files with indirect coverage changes

@mountiny
Copy link
Contributor Author

@codex review

@mountiny
Copy link
Contributor Author

@huult @TMisiukiewicz ready

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac0b5176d4

ℹ️ 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".

clearActiveTransactionIDs();
};
}, [visualOrderTransactionIDsDeepCompare]);
}, [visualOrderTransactionIDs]);

Choose a reason for hiding this comment

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

P2 Badge Avoid clearing active IDs on referential rerenders

Using visualOrderTransactionIDs as a raw useEffect dependency makes this effect rerun whenever the array reference changes, even if the IDs are unchanged; on each rerun React executes the cleanup first, so clearActiveTransactionIDs() writes null before setting the same IDs again. Because cleanup resets the new lastSetIDs cache, the idempotent guard in setActiveTransactionIDs cannot short-circuit these same-content rerenders, which reintroduces extra Onyx churn and can briefly drop prev/next transaction context in the RHP.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 9cb1ede — split the effect into two:

  1. Set effect ([visualOrderTransactionIDs] dep) — calls setActiveTransactionIDs on changes; no cleanup.
  2. Unmount-only effect ([] dep) — calls clearActiveTransactionIDs only when the component unmounts.

This eliminates the null → same-IDs flash on referential re-renders since clearActiveTransactionIDs no longer runs during the cleanup phase of re-fires. The idempotent guard in setActiveTransactionIDs still prevents redundant Onyx writes when the content hasn't changed.

Tests updated accordingly — the reference-change test now explicitly asserts that clearActiveTransactionIDs is NOT called on re-render.

…nder

When visualOrderTransactionIDs changes by reference only (same content),
the previous combined effect would clear → re-set the IDs, causing a brief
null state in Onyx. By separating clearActiveTransactionIDs into its own
unmount-only effect, referential re-renders only call setActiveTransactionIDs
(which the idempotent guard skips) without touching the clear path.

Made-with: Cursor
useEffect cleanup functions must return void, not Promise<void>.
The arrow shorthand was implicitly returning the promise from
clearActiveTransactionIDs(). Wrapping in a block body discards it.

Made-with: Cursor
@huult
Copy link
Contributor

huult commented Feb 26, 2026

Reviewing...

Comment on lines +20 to +23
if (lastSetIDs?.length === ids.length && lastSetIDs.every((id, i) => id === ids.at(i))) {
return Promise.resolve();
}
lastSetIDs = ids;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (lastSetIDs?.length === ids.length && lastSetIDs.every((id, i) => id === ids.at(i))) {
return Promise.resolve();
}
lastSetIDs = ids;
// Create a shallow copy to avoid reference mutation
const idsCopy = [...ids];
if (lastSetIDs?.length === idsCopy.length &&
lastSetIDs.every((id, i) => id === idsCopy.at(i))) {
return Promise.resolve();
}
lastSetIDs = idsCopy;

What do you think about creating a shallow copy to avoid reference mutation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I don't think the shallow copy is needed here because:

  1. The ids argument always comes from visualOrderTransactionIDs, which is a useMemo result — React convention treats these as immutable (replaced on change, never mutated in-place).
  2. The elements are primitive strings, so they can't be mutated individually.
  3. It would add an allocation on every call, including when the idempotent guard short-circuits — which works against the goal of reducing unnecessary work.

If the caller were external/untrusted I'd agree with defensive copying, but since this is an internal action called only from a single useEffect, the extra copy doesn't buy us correctness here.

@huult
Copy link
Contributor

huult commented Feb 26, 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
Screen.Recording.2026-02-26.at.14.57.57.mp4
Android: mWeb Chrome
Screen.Recording.2026-02-26.at.15.02.24.mp4
iOS: HybridApp
iOS: mWeb Safari
Screen.Recording.2026-02-26.at.15.07.24.mp4
MacOS: Chrome / Safari
Screen.Recording.2026-02-26.at.14.51.02.mp4

@mountiny
Copy link
Contributor Author

@huult addressed your comment, did it test well for you?

@huult
Copy link
Contributor

huult commented Feb 26, 2026

@mountiny Yes, I tested it and it works well. I didn’t see any issues

Copy link
Contributor

@huult huult left a comment

Choose a reason for hiding this comment

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

LGTM

@melvin-bot melvin-bot bot requested a review from mollfpr February 26, 2026 23:15
@melvin-bot
Copy link

melvin-bot bot commented Feb 26, 2026

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

@mountiny
Copy link
Contributor Author

Thank you! @huult

@mollfpr mollfpr merged commit 651201c into main Feb 27, 2026
35 of 37 checks passed
@mollfpr mollfpr deleted the vit-removeDeepCompareRef-transactionList branch February 27, 2026 04:02
@github-actions
Copy link
Contributor

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

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mollfpr in version: 9.3.27-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Mar 2, 2026

🚀 Deployed to production by https://github.com/blimpich in version: 9.3.27-8 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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.

6 participants