Skip to content

[HOLD for payment 2024-07-10] [$250] Chat does not scroll to the last message when a new message received #43600

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.82-0
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @youssef-lr
Slack conversation:

Action Performed:

  1. Go to a report with lots of messages
  2. Send a message to user B

Expected Result:

For user B the chat scrolls to the last message received

Actual Result:

Does not scroll

Workaround:

unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

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

Screenshots/Videos

Recording.205.mp4
Screen.Recording.2024-06-11.at.21.37.40.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0178751bd086a2062a
  • Upwork Job ID: 1802672136974977044
  • Last Price Increase: 2024-06-17
  • Automatic offers:
    • s77rt | Reviewer | 102816257
    • tsa321 | Contributor | 102816260
Issue OwnerCurrent Issue Owner: @bfitzexpensify

Activity

  1. added
    Daily
    Bug
    on Jun 12, 2024
  2. melvin-bot commented on Jun 12, 2024

    @melvin-bot

    Triggered auto assignment to @bfitzexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. tsa321 commented on Jun 16, 2024

    @tsa321
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Chat does not scroll to the last message when a new message received

    What is the root cause of that problem?

    When user receive new message, the pushJSON data contains onyx update for report and the new reportAction.
    The report onyx data will update lastVisibleAcitonCreated and reportAction will add new latest reportAction.
    In here:

    const hasNewestReportAction = lodashGet(reportActions[0], 'created') === props.report.lastVisibleActionCreated;

    when onyx update on report data the hasNewestReportAction will be false because the reportActions isn't updated yet, then the onyx will update reportActions which will make hasNewestReportAction to be true. So there is toggling false then true after the complete update of data from push event.

    The hasNewestReportAction will affect enableAutoscrollToTopThreshold value, which is the scrolling logic depends on.

    In here:

    if (mvcpAutoscrollToTopThreshold != null && scrollOffset <= mvcpAutoscrollToTopThreshold) {
    scrollToOffset(0, true);

    when the pushData update completed, the mvcpAutoscrollToTopThreshold value used in here isn't the latest mvcpAutoscrollToTopThreshold. the value is still undefined because of the update from report onyx data and hasn't been updated after reportAction onyx merged. So when the delta value is higher 0.5 / new message inserted in list, the value of mvcpAutoscrollToTopThreshold hasn't been updated.


    Since the `adjustForMaintainVisibleContentPosition` is used in subscriber of `MutationObserver`, we need the updated value right at when message is inserted into the list. So we need the latest value and using ref here can solve the issue. If we are using useCallback that depend on the `mvcpAutoscrollToTopThreshold` the new subscriber will be created and will disturb detection in `mutationObserver` when observing the list content difference. Sometimes I noticed, when new subscriber based on new callback produced by useCallback, the list is already changes and delta difference is still 0. So we must remove the dependency of `mvcpAutoscrollToTopThreshold` in `adjustForMaintainVisibleContentPosition` and use ref of mvcpAutoscrollToTopThreshold.

    What changes do you think we should make in order to solve the problem?

    We must remove the dependency of mvcpAutoscrollToTopThreshold in adjustForMaintainVisibleContentPosition and we could use ref of mvcpAutoscrollToTopThreshold at the top of the function component and immediately update it when new mvcpAutoscrollToTopThreshold available, then use it inside adjustForMaintainVisibleContentPosition

    The code could be:

    const mvcpAutoscrollToTopThresholdRef = useRef(mvcpAutoscrollToTopThreshold);
    mvcpAutoscrollToTopThresholdRef.current = mvcpAutoscrollToTopThreshold;
    ....
    // then in adjustForMaintainVisibleContentPosition:
    if (mvcpAutoscrollToTopThresholdRef.current != null && scrollOffset <= mvcpAutoscrollToTopThresholdRef.current) {
         scrollToOffset(0, true);
    }

    and we must remove mvcpAutoscrollToTopThreshold in :

    }, [getScrollOffset, scrollToOffset, mvcpMinIndexForVisible, mvcpAutoscrollToTopThreshold, horizontal]);


    Other alternative is (workaround):

    We could use useMemo to avoid unnecessary value changes on hasNewestReportAction when the onyx pushJSON data isn't fully merged yet.

    In here, the code could be:

    const hasNewestReportAction = useMemo(() => lodashGet(reportActions[0], 'created') === props.report.lastVisibleActionCreated, [reportActions.length]);

    So when new report action is updated, the shouldEnableAutoScroll that depend on hasNewestReportAction will keep on true and the List will scroll.

  4. added
    External
    on Jun 17, 2024
  5. changed the title [-]Chat does not scroll to the last message when a new message received[/-] [+][$250] Chat does not scroll to the last message when a new message received[/+] on Jun 17, 2024
  6. melvin-bot commented on Jun 17, 2024

    @melvin-bot
  7. added
    Help Wanted
    on Jun 17, 2024
  8. melvin-bot commented on Jun 17, 2024

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @s77rt (External)

  9. s77rt commented on Jun 17, 2024

    @s77rt
    Member

    I'm not able to reproduce the bug. @tsa321 Is this still reproducible for you?

    Screen.Recording.2024-06-17.at.11.50.57.PM.mov
  10. tsa321 commented on Jun 17, 2024

    @tsa321
    Contributor

    @s77rt yes, I can still reprdouce it. You must scroll up to 1 or 2 messages above before receiving new message.

    macos-web-d.mp4
  11. 23 remaining items

  12. tsa321 commented on Jun 28, 2024

    @tsa321
    Contributor

    @s77rt Currently, I am not with my computer, but I am guessing that the PR causing the issue is #42592
    For the comment linking should also check on #44412

  13. s77rt commented on Jun 29, 2024

    @s77rt
    Member

    @tsa321 I see, this is related to React.StrictMode which makes the bug dev only. This is a regression from that PR then.

  14. added
    Weekly
    Awaiting Payment
    and removed
    Weekly
    on Jul 3, 2024
  15. changed the title [-][$250] Chat does not scroll to the last message when a new message received[/-] [+][HOLD for payment 2024-07-10] [$250] Chat does not scroll to the last message when a new message received[/+] on Jul 3, 2024
  16. removed
    Reviewing
    on Jul 3, 2024
  17. melvin-bot commented on Jul 3, 2024

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  18. melvin-bot commented on Jul 3, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.3-7 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2024-07-10. 🎊

    For reference, here are some details about the assignees on this issue:

  19. melvin-bot commented on Jul 3, 2024

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@s77rt] The PR that introduced the bug has been identified. Link to the PR:
    • [@s77rt] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@s77rt] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@s77rt] Determine if we should create a regression test for this bug.
    • [@s77rt] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@bfitzexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  20. s77rt commented on Jul 7, 2024

    @s77rt
    Member
  21. added
    Daily
    and removed
    Weekly
    on Jul 10, 2024
  22. bfitzexpensify commented on Jul 10, 2024

    @bfitzexpensify
    Contributor

    Payments complete. Closing this one out.

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions