Skip to content

[NoQA] Fix "Maximum update depth exceeded" crash in the LHN provider - #106383

Merged
mountiny merged 4 commits into
Expensify:mainfrom
abbasifaizan70:fix/104504-lhn-cache-ref-and-stable-entries
Nov 13, 2026
Merged

mountiny merged 4 commits into
Expensify:mainfrom
abbasifaizan70:fix/104504-lhn-cache-ref-and-stable-entries

Conversation

@abbasifaizan70

@abbasifaizan70 abbasifaizan70 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

…eport attributes on content

Explanation of Change

On web, SidebarOrderedReportsContextProvider could crash with React #185 during bursts of Onyx writes. React counts commits that leave another update pending and throws after 50 in a row. Every Onyx-driven render of this provider is a synchronous commit whose passive effects run inside the commit, so the setCurrentReportsToDisplay in the cache effect left an update pending after each one — and the memo returned a new map on every commit whenever an unread/GBR/RBR chat was displayed, even when nothing changed.

  • Cache stored during render instead of from an effect. The LHN cache is only the starting point of the next incremental run, so it is now updated with a conditional setState right after the memo. React re-runs the render before committing, nothing is left pending, and the counter can't grow. (A ref would also work but the react-hooks/refs lint rule disallows reading it during render.)
  • Flagged entries are reused when unchanged. They are spread copies of the report, and the old check compared the copy to the raw report, which never matched. A WeakMap now remembers each copy's source report, and the entry is reused when the report, the three flags and lastVisibleActionCreatedForInboxTab are unchanged, so a no-op recheck returns the same map.
  • Report attributes are read through a content-gated reference. REPORT_ATTRIBUTES is rewritten with a new object on every recompute; the memo, getUpdatedReports, the sort and the brick road now read a reference that only advances when the existing value diff reports a change.
  • Review edge cases. When the focused report changes, the previous and new report and their parents are rechecked (a thread's parent stays in the LHN only while the thread is open). The sort memo now lists every input that only affects the order (priorityMode, and a stable set of archived report IDs derived from reportNameValuePairs). On main these were excluded behind an eslint-disable, so switching to #focus with the same chats eligible kept the old order; covered by a test that fails on main.

The react-hooks/set-state-in-effect seatbelt entry for this file is removed because the effect is gone.

Fixed Issues

$ #104504
PROPOSAL: #104504 (comment)

Tests

  • Verify that no errors appear in the JS console
  1. Sign in on web with an account that has a few chats. Open Inbox, open the console.
  2. Make sure at least one chat is bold (unread). If none is, mark Concierge unread locally:
    const id = await Onyx.get('conciergeReportID');
    await Onyx.merge(`report_${id}`, {lastReadTime: '2026-10-13 00:00:00.000'});
  3. Send that chat a burst of updates with nothing but microtasks between them:
    let p = Promise.resolve();
    for (let i = 0; i < 120; i++) {
        p = p.then(() => {
            Onyx.merge(`report_${id}`, {lastVisibleActionCreated: `2026-10-13 23:52:${String(26 + (i % 30)).padStart(2, '0')}.${String(i).padStart(3, '0')}`});
        });
    }
  4. Verify the app keeps working and the console shows no "Maximum update depth exceeded" error. (On main this shows the "Uh-oh, something went wrong!" page within a second.)
  5. Open a chat, open a thread from one of its messages, then go back out of the thread. Verify the LHN updates normally and the parent chat is still correct.
  6. Settings → Preferences → Priority mode: switch to #focus and back. Verify the list re-orders (alphabetical in #focus, most recent otherwise) each time.
  7. Have a second account send a message to a chat and to a single-expense report's thread. Verify both show up bold and under the Unread tab.

Offline tests

Same as tests.

QA Steps

  • Verify that no errors appear in the JS console

N/A

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 verified any copy / text that was added to the app 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • 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)
  • 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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 Screenshot 2026-11-10 at 4 49 53 AM
Android: mWeb Chrome

Same fix as web; the repro needs the browser console, which isn’t accessible on this platform.

iOS: Native Screenshot 2026-11-10 at 4 45 00 AM
iOS: mWeb Safari

Same fix as web; the repro needs the browser console, which isn’t accessible on this platform.

MacOS: Chrome / Safari
Screen.Recording.2026-11-10.at.4.29.52.AM.mov

Screenshot 2026-11-10 at 4 30 51 AM

@abbasifaizan70
abbasifaizan70 force-pushed the fix/104504-lhn-cache-ref-and-stable-entries branch from 1c9aab5 to 9944708 Compare November 9, 2026 23:05
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/hooks/useSidebarOrderedReports.tsx 88.72% <100.00%> (+1.09%) ⬆️
src/libs/SidebarUtils.ts 95.49% <100.00%> (+0.69%) ⬆️
src/libs/getReportAttributesUpdates.ts 100.00% <100.00%> (ø)
... and 433 files with indirect coverage changes

@abbasifaizan70
abbasifaizan70 force-pushed the fix/104504-lhn-cache-ref-and-stable-entries branch from 9944708 to e8290b2 Compare November 9, 2026 23:30
@abbasifaizan70 abbasifaizan70 changed the title 104504: Keep the LHN cache in a ref, stabilize flagged LHN entries and gate r… 104504: Fix "Maximum update depth exceeded" crash in the LHN provider Nov 9, 2026
@abbasifaizan70
abbasifaizan70 marked this pull request as ready for review November 9, 2026 23:53
@abbasifaizan70
abbasifaizan70 requested review from a team as code owners November 9, 2026 23:53
@melvin-bot
melvin-bot Bot requested review from huult and removed request for a team November 9, 2026 23:53
@melvin-bot

melvin-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

@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 requested review from JmillsExpensify and removed request for a team November 9, 2026 23:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T02:13:03.661493Z 98a277e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@huult

huult commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@abbasifaizan70 Could you shorten the comment? If it's not necessary, we can remove it.

@huult

huult commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot review this

@huult

huult commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@codex review this

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 98a277e703

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ⚠️ partial

Verified basic navigation on dev NewDot web, but not the PR's update-loop regression. Required scripting, console access, offline control, and second-account fixtures were unavailable.

Account page with Preferences visible but unavailable through tested selectors

Step Status
1. Signed-in Inbox displays chatsInbox opened, but only Concierge was available—not several chats. Console inspection was unsupported.
Inbox with a single Concierge conversation
❌
2. Confirm an unread/bold chatNo unread fixture was confirmed. Direct Onyx scripting was unavailable.
❌
3. Run 120 microtask-separated Onyx updatesBlocked by unsupported scripting; no substitute actions were used.
❌
4. Verify stability after the burstUnverified because the burst could not run. Basic navigation remained responsive.
❌
5. Enter and leave a message threadConcierge history opened, but no accessible thread fixture was available.
❌
6. Switch priority mode and verify orderingPreferences appeared visually, but tested selectors could not access it. Ordering was not verified.
Account page with Preferences visible but unavailable through tested selectors
❌
7. Verify incoming messages under UnreadBlocked: second-account and single-expense-thread fixtures were unavailable.
❌
8. Repeat offlineBlocked: offline network control was unavailable.
❌
9. Verify no JavaScript console errorsUnverified: console diagnostics were unavailable. These incomplete checks do not establish a product regression or validate the fix.
❌

view run

@mountiny
mountiny requested a review from sosek108 November 10, 2026 04:11

@JmillsExpensify JmillsExpensify left a comment

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.

No product review required.

@huult

huult commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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 any copy / text that was added to the app 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • 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)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • 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
    • 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 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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-11-11.at.09.48.20.mov
Android: mWeb Chrome
Screen.Recording.2026-11-11.at.09.49.58.mov
iOS: HybridApp
Screen.Recording.2026-11-11.at.09.55.08.mov
iOS: mWeb Safari
Screen.Recording.2026-11-11.at.09.57.42.mov
MacOS: Chrome / Safari
Screen.Recording.2026-11-11.at.09.39.29.mov

Comment thread src/hooks/useSidebarOrderedReports.tsx Resolved
Comment thread src/hooks/useSidebarOrderedReports.tsx Resolved
Comment thread src/hooks/useSidebarOrderedReports.tsx Resolved
Comment thread src/hooks/useSidebarOrderedReports.tsx Resolved
Comment thread src/hooks/useSidebarOrderedReports.tsx Resolved
@sosek108

Copy link
Copy Markdown
Contributor

Nice work! The root cause analysis seems solid. My comments are small and not blocking. The one thing that actually can have the perf impact is reportNameValuePairs I commented here #106383 (comment).

Keep in mind I won't be working tomorrow (Independence Day) but I don't there is need for another review from me.

@abbasifaizan70

Copy link
Copy Markdown
Contributor Author

@sosek108 @huult Addressed all review comments

@huult

huult commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@abbasifaizan70 I don't think QA can test this normally, so could you update the QA steps to N/A and add [No QA] to the PR title?

@huult huult left a comment

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.

LGTM.

@melvin-bot
melvin-bot Bot requested a review from mountiny November 11, 2026 03:00
@huult

huult commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

NAB #106383 (comment)

@mountiny mountiny changed the title 104504: Fix "Maximum update depth exceeded" crash in the LHN provider [NoQA] Fix "Maximum update depth exceeded" crash in the LHN provider Nov 11, 2026

@mountiny mountiny left a comment

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.

@sosek108 Can you do a final review now? thanks!

@huult

huult commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Nice work! The root cause analysis seems solid. My comments are small and not blocking. The one thing that actually can have the perf impact is reportNameValuePairs I commented here #106383 (comment).

Keep in mind I won't be working tomorrow (Independence Day) but I don't there is need for another review from me.

@mountiny It looks like he has already approved it

@mountiny

Copy link
Copy Markdown
Contributor

I would like to make sure to measure the performance of these changes, @sosek108 could help to measure it on some supportalled big account

@sosek108

Copy link
Copy Markdown
Contributor

I'm starting performance testing right now

@huult

huult commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

I'm starting performance testing right now

@sosek108 Please let us know if you find any issues.

@sosek108

Copy link
Copy Markdown
Contributor

Sorry, I've had problems running semi automated tests as the app for me today was flaky.

In the end I've successfully measured. Tests AB/BA so I tested main -> branch and branch -> main for more data.

  • ManualAppStartup: -4,5% but individual samples were overlapping
  • ManualOpenReport: -6,2% but individual samples were also overlapping
    When results are overlapping there is a chance that this result is noise.

Conclusion is that this PR does not decrease and may slightly improve performance

Please, keep in mind that I will be on sick leave tomorrow

@mountiny mountiny left a comment

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.

Perfect, thanks for testing and I hope you will feel better soon

@mountiny
mountiny merged commit 94e7794 into Expensify:main Nov 13, 2026
41 of 50 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

Copy link
Copy Markdown
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.

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.38-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR fixes a crash and restores expected chat ordering and unread behavior without adding a feature, changing a workflow, or making existing article text incorrect.


view run

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.

7 participants