Skip to content

Conversation

@chrispader
Copy link
Contributor

@chrispader chrispader commented Nov 26, 2025

@rlinoz @ishpaul777

Explanation of Change

This PR changes the behavior of useLoadReportActions so that GetOlderActions and GetNewerActions can be triggered multiple times. Previously, this could only be triggered once, i'm not sure if this was by design or a bug, but for comment linking this definitely has to be possible.

Fixed Issues

$ #35011
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Before these tests, you might want to log in freshly or clear the reportActions_ and reportActionsPages_ Onyx stores for a given report:

Load older chats

  1. Open a report
  2. Scroll to the oldest message / begin of the chat until new messages are loaded.
  3. Repeat 2-3 times
  4. Make sure, that new messages are loaded and the chat behaves as expected.

Load older/newer chats for linked messages

  1. Open a report with a old linked report action ID (/r/:reportID/:reportActionID)
  2. Scroll to the oldest message / begin of the chat until new messages are loaded.
  3. Make sure that older messages are loaded
  4. Scroll to the end of the chat
  5. Make sure that newer messages are loaded
  6. Repeat both older and newer 2-3 times or until the end of the chat is reached.

Offline tests

None needed.

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

Same as in Tests.

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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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

@chrispader chrispader force-pushed the @chrispader/allow-multiple-loads-in-useLoadReportActions-hook branch from 42e8ae6 to 752818e Compare November 26, 2025 09:18
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/API/index.ts 92.55% <100.00%> (-0.16%) ⬇️
src/pages/home/report/ReportActionsView.tsx 76.92% <ø> (ø)
...utils/chatContentScrollViewPlatformStyles/index.ts 0.00% <ø> (ø)
src/hooks/useLoadReportActions.ts 84.00% <80.00%> (+0.66%) ⬆️
src/libs/actions/Report.ts 55.21% <50.00%> (ø)
... and 22 files with indirect coverage changes

@chrispader chrispader marked this pull request as ready for review November 26, 2025 09:35
@chrispader chrispader requested review from a team as code owners November 26, 2025 09:35
@melvin-bot melvin-bot bot requested review from aimane-chnaif and removed request for a team November 26, 2025 09:35
@melvin-bot
Copy link

melvin-bot bot commented Nov 26, 2025

@aimane-chnaif 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 trjExpensify and removed request for a team November 26, 2025 09:35
],
);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic Error

There's a logic error in this useEffect. When !isTransactionThreadReport is true (line 191), you're checking if both isNewestReportActionLoaded AND isNewestTransactionThreadReportActionLoaded are loaded before setting isLoadingNewerChats.current = false (lines 194-197).

However, if it's NOT a transaction thread report, you shouldn't need to check the transaction thread's newest action at all. The code on lines 192-197 appears unreachable/incorrect because:

  1. Line 192 sets isLoadingNewerChats.current = false unconditionally
  2. Lines 193-197 declare a variable and then check both reports, which contradicts the !isTransactionThreadReport condition

This should probably be:

if (!isTransactionThreadReport) {
    const isNewestReportActionLoaded = isReportActionLoaded(currentReportNewest?.reportActionID);
    if (isNewestReportActionLoaded) {
        isLoadingNewerChats.current = false;
    }
    return;
}

const isNewestReportActionLoaded = isReportActionLoaded(currentReportNewest?.reportActionID);
const isNewestTransactionThreadReportActionLoaded = isReportActionLoaded(transactionThreadNewest?.reportActionID);

if (isNewestReportActionLoaded && isNewestTransactionThreadReportActionLoaded) {
    isLoadingNewerChats.current = false;
}


return reportActions.some((action) => action.reportActionID === actionID);
},
[reportActions],
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing useEffect Import

The diff shows that useEffect is imported at line 2, but this comment is about line 92 in the new code. Looking at the logic of the new isReportActionLoaded callback:

This callback iterates through ALL reportActions using .some() to check if a specific action exists. For large reports with thousands of actions, this could be expensive and is called multiple times in the useEffect hooks.

Performance Suggestion: Consider memoizing a Set of reportActionIDs to make lookups O(1) instead of O(n):

const reportActionIDsSet = useMemo(() => {
    return new Set(reportActions.map((action) => action.reportActionID));
}, [reportActions]);

const isReportActionLoaded = useCallback(
    (actionID: string | undefined) => {
        if (!actionID) {
            return true;
        }

        return reportActionIDsSet.has(actionID);
    },
    [reportActionIDsSet],
);

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 point. Thanks for the catch!

);

useEffect(() => {
if (!isLoadingOlderChats.current) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential Race Condition

The new implementation uses useEffect to reset the isLoadingOlderChats.current flag when new actions are loaded. However, there's a potential race condition:

  1. User triggers loadOlderChats() which sets isLoadingOlderChats.current = true and calls getOlderActions()
  2. The API call is in-flight
  3. User triggers loadOlderChats() again before the first request completes
  4. The check at line 102 (isLoadingOlderChats.current) blocks the second call
  5. First request completes, useEffect at line 124 runs and sets isLoadingOlderChats.current = false
  6. But what if the actions from the first request arrive in Onyx BEFORE the useEffect runs?

The timing between when Onyx updates reportActions and when the useEffect detects the change could cause issues. Consider adding error handling or using a more robust loading state management pattern (e.g., tracking request IDs or using a proper state machine).

@chrispader
Copy link
Contributor Author

chrispader commented Nov 26, 2025

In order to prevent duplicate concurrent GetNewerActions/GetOlderActions API calls, we need to check whether the request has finished/failed. Previously, i used the promises from the API.paginate call, but this is disregarded as per this rule in the data binding guidelines

With that in mind, i changed the implementation to prevent further API calls until the report action is loaded and found in Onyx, but this raises some problems:

Therefore, i'd like to know if we can make an exception for the rule above for this purpose and we just go with the previous promise-based implementation. We are not awaiting any data from a previous action or API request, we just want to check whether it has finished. (Success or failure don't make a difference here)

cc @rlinoz @ishpaul777

@rlinoz rlinoz removed the request for review from aimane-chnaif November 26, 2025 14:17
@chrispader
Copy link
Contributor Author

bug: Dev Error when scrolling down from a chat with many messages likely cause scroll to last of chat

@ishpaul777 i'm not able to reproduce this one. Maybe because i just merged main as well?

Tried both with existing report actions and pages in cache, and after clearing cache.

Screen.Recording.2025-12-05.at.12.52.36.mov
Screen.Recording.2025-12-05.at.12.51.37.mov

@chrispader
Copy link
Contributor Author

bug?: There is no loading skelaton when loading report instead it shows first few actions while its loading

@ishpaul777 also not able to reproduce 🥴

Screen.Recording.2025-12-05.at.12.54.58.mov

@ishpaul777
Copy link
Contributor

ishpaul777 commented Dec 5, 2025

bug: Dev Error when scrolling down from a chat with many messages likely cause scroll to last of chat

Screen.Recording.2025-12-06.at.12.20.02.AM.mov

bug?: There is no loading skelaton when loading report instead it shows first few actions while its loading

Screen.Recording.2025-12-06.at.12.18.57.AM.mov

Both issue still reprodicble consistently 😕

@chrispader
Copy link
Contributor Author

chrispader commented Dec 9, 2025

bug?: There is no loading skelaton when loading report instead it shows first few actions while its loading

Okay @ishpaul777 so i'm able to reproduce this now, but this is also present on main atm. Could you please confirm? 👀

bug: Dev Error when scrolling down from a chat with many messages likely cause scroll to last of chat

Still not able to reproduce this one unfortunately. I tried on both Chrome and Arc (both Chromium based), tried logging in and out a couple of times, clearing (Onyx) cache, both from within DevTools and the Troubleshoot menu. Also, i think you were either on a slow network connection or enabled Network throttling, so i also tried with 3G network throttling. Do you have any further repro steps for me?

I'm suspecting this is to some illegal/stale state in your Expensify instance. Could you try logging out completely maybe?

Screen.Recording.2025-12-09.at.11.22.55.mov

@rlinoz
Copy link
Contributor

rlinoz commented Dec 15, 2025

Hey @ishpaul777 were you able to check this out? #76104 (comment)

@ishpaul777
Copy link
Contributor

Okay @ishpaul777 so i'm able to reproduce this now, but this is also present on main atm. Could you please confirm? 👀

ahh i confirm its reproducible on staging and prod also

Screen.Recording.2025-12-15.at.8.22.33.PM.mov

bug: Dev Error when scrolling down from a chat with many messages likely cause scroll to last of chat

@chrispader would you like to try testing with my test account, i am able to reproduce this very reliably, please check below recording. on first opening chat it doesn't scroll below 150th message(i just this is also reproducible on staging also,) later when reopening chat it scroll directly to last message (not reproducbile on staging)

Screen.Recording.2025-12-15.at.8.32.03.PM.mov

@chrispader
Copy link
Contributor Author

@chrispader would you like to try testing with my test account

Yes, that would be awesome. thanks!

@rlinoz
Copy link
Contributor

rlinoz commented Dec 18, 2025

Hey @chrispader were you able to test it?

@chrispader
Copy link
Contributor Author

chrispader commented Dec 18, 2025

Yes, so i was talking with @ishpaul777 and these is the issue in more details according to him:

So without cache linking to 1st message it:

  1. its scrolls to first message It does not stay is view
  2. When scrolling down after 150th message

Again reopening chat and linking to message

  1. When. Scrolling down it suddenly jump to end of chat

After testing on my and @ishpaul777's account i was able to reproduce parts of the issue:

  1. its scrolls to first message It does not stay is view

I was able to reproduce this, but i can also repro on main. This is something that should be fixed by #51366, because there we change the initial rendering of the InvertedFlatList that is used in the ReportScreen. So i would not block this PR on this issue.

  1. When scrolling down after 150th message

and

Again reopening chat and linking to message

  1. When. Scrolling down it suddenly jump to end of chat

I am still not able to reproduce this one. Here's a screen recording of the whole reproduction steps flow after clearing the cache.

Screen.Recording.2025-12-18.at.10.21.57.mov

I can even see that an issue currently on main was fixed by this PR. Previously, we would only allow one GetNewerActions API request to be triggered, therefore, when linking to the first message and then scrolling down it would just stop at message 150, because there are no more messages being loaded after that.

Screen.Recording.2025-12-18.at.10.50.23.mov

So if the jumps to the end of the chat are not reproducible, i think we should be good with merging this.

@ishpaul777
Copy link
Contributor

finishing this up today!

Copy link
Contributor

@ishpaul777 ishpaul777 left a comment

Choose a reason for hiding this comment

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

So if the jumps to the end of the chat are not reproducible, i think we should be good with merging this.

this was still reproducible for me on chrome everytime chat is open first time after sign in but it could be me only thing 🤷

rest LGTM! Thanks!

@rlinoz
Copy link
Contributor

rlinoz commented Dec 29, 2025

Hey @chrispader I am facing the same issue that Ishpaul is. Maybe we can screenshare and get this sorted?

Screen.Recording.2025-12-29.at.10.24.14.mov

@chrispader
Copy link
Contributor Author

@rlinoz @ishpaul777 going to look into this again. That's a nasty one 😅

@rlinoz
Copy link
Contributor

rlinoz commented Jan 7, 2026

@chrispader let me know if I can help debug this 😄

@rlinoz
Copy link
Contributor

rlinoz commented Jan 9, 2026

Hey @chrispader any updates on this?

@chrispader
Copy link
Contributor Author

Hey @chrispader any updates on this?

@rlinoz sorry for the delay, i will try to debug this again today and hopefully find a fix over the weekend, otherwise ask you to debug it for me too 🙌🏼

@chrispader
Copy link
Contributor Author

@rlinoz @ishpaul777 i'm looking into this again now. Sorry for the delay

@chrispader
Copy link
Contributor Author

Okay, so it seems both @rlinoz and @ishpaul777 you're able to reproduce the issue where no messages after the 150th message are loaded when scrolling down, right?

The issue where the chat jumps to the end of the chat on scroll seems to be resolved right?

@chrispader
Copy link
Contributor Author

chrispader commented Jan 12, 2026

@rlinoz @ishpaul777 i've retested on Chrome, but i'm still not able to reproduce 🥴

I've cleared cache and then went to the chat and clicked on a link to somewhere in the middle of the chat. I first scrolled up, causing two triggers of GetOlderActions. After reaching the start of the chat, i scrolled down until i was able to trigger GetNewerActions twice.

Screen.Recording.2026-01-12.at.13.02.41.mov

Sometimes in between the content stalled, but that's mainly due to the network request taking some time and me continuing to scroll.

(we should probably implement some sort of loading spinner to show while the request is loading, i've proposed that before in Slack, maybe i can work on this in a follow-up)

@chrispader
Copy link
Contributor Author

chrispader commented Jan 12, 2026

@rlinoz I have just tried to repro in Firefox as well and encountered the same issue that we've fixed before, where scrolling down stops at some point due to the content being cut off. We have fixed that before in this commit:

a42da60

import type ChatContentScrollViewPlatformStyles from './types';

const chatContentScrollViewPlatformStyles: ChatContentScrollViewPlatformStyles = {
-    overflow: 'hidden',
+    overflowY: 'clip',
};

export default chatContentScrollViewPlatformStyles;

I'all add this change to this PR as well, @rlinoz could you re-test or do you have time to screenshare later today, so we can figure this out?

@chrispader chrispader requested a review from a team as a code owner January 12, 2026 13:23
@rlinoz
Copy link
Contributor

rlinoz commented Jan 12, 2026

Fixed for me! 🎉

Can you double check @ishpaul777, please?

@ishpaul777
Copy link
Contributor

Acknowledging i saw this, will retest ASAP!

@ishpaul777
Copy link
Contributor

Reviewing now!

@ishpaul777
Copy link
Contributor

ishpaul777 commented Jan 15, 2026

Apologies i shifted focus on other issues. it seems like now i cant even scroll after the 51st message

demo.mov

i reverted this overflow back to 'hidden' and its fixed but still has this #76104 (comment) issue

this is also repro on Safari browser, but in this case it tries scrolls up while user is scrolling down and then auto scroll to last

Screen.Recording.2026-01-16.at.5.16.05.AM.mov

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.

3 participants