Skip to content

regression: fix jump from pseudo message lists #35880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ggazzo
Copy link
Member

@ggazzo ggazzo commented Apr 25, 2025

Proposed changes (including videos or screenshots)

Introduced here: #35818

Issue(s)

Steps to test or reproduce

Further comments

CORE-1098
CORE-1099


This pull request addresses a regression issue related to message list navigation in the Rocket.Chat application. The changes focus on improving the user experience when loading older messages by implementing scroll position saving and restoration within the RoomHistoryManager. Specifically, the current scroll position is saved when older messages are loaded using the getMore method, and a new restoreScroll method is introduced to adjust for content height changes. Additionally, a loaded-messages event is emitted after messages are loaded in both getMore and getMoreNext, and a utility function waitAfterFlush is added.

In the useJumpToMessage hook, modifications are made to enhance listRef handling and message scrolling behavior. The useGetMore hook is refactored to use async/await for fetching older messages, introduces flushSync for smoother scroll restoration, and optimizes performance by adding passive: true to the scroll listener. The throttled handler is also ensured to be cancelled on unmount. These improvements aim to enhance the history loading mechanism, although further enhancements in type safety and error handling are suggested.

Copy link
Contributor

dionisio-bot bot commented Apr 25, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Apr 25, 2025

⚠️ No Changeset found

Latest commit: bee60e1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

kodus-ai bot commented Apr 25, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@@ -14,26 +15,35 @@ export const useGetMore = (rid: string, atBottomRef: MutableRefObject<boolean>)

const refValue = ref.current;

const handleScroll = withThrottling({ wait: 100 })((event) => {
const handleScroll = withThrottling({ wait: 100 })(async (event) => {
const lastScrollTopRef = event.target.scrollTop;
Copy link

Choose a reason for hiding this comment

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

kody code-review Potential Issues high

async (event: React.UIEvent<HTMLElement>) => {
  const target = event.target;
  if (!(target instanceof HTMLElement)) {
    return;
  }
  const lastScrollTopRef = target.scrollTop;
  const height = target.clientHeight;
  // ...
  } else if (hasMoreNext === true && Math.ceil(lastScrollTopRef) >= target.scrollHeight - height) {

Accessing properties like scrollTop, clientHeight, and scrollHeight directly from event.target assumes it's an Element with these properties, which can lead to runtime errors if the target is not the expected type.

This issue appears in multiple locations:

  • apps/meteor/client/views/room/body/hooks/useGetMore.ts: Lines 19-35
  • apps/meteor/client/views/room/body/hooks/useGetMore.ts: Lines 19-35
    Please add a type check (e.g., instanceof HTMLElement) at the beginning of the handler to validate event.target and prevent potential runtime errors.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines +30 to +34
await RoomHistoryManager.getMore(rid);

flushSync(() => {
RoomHistoryManager.restoreScroll(rid);
});
Copy link

Choose a reason for hiding this comment

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

kody code-review Error Handling high

try {
  await RoomHistoryManager.getMore(rid);
  flushSync(() => {
    RoomHistoryManager.restoreScroll(rid);
  });
} catch (error) {
  console.error('Failed to get more room history:', error);
  // Optional: Implement user feedback mechanism
}

The await RoomHistoryManager.getMore(rid) call could potentially reject (e.g., due to network issues), leading to unhandled promise rejections.

This issue appears in multiple locations:

  • apps/meteor/client/views/room/body/hooks/useGetMore.ts: Lines 30-34
  • apps/meteor/client/views/room/body/hooks/useGetMore.ts: Lines 30-34
    Please wrap the asynchronous operation and the subsequent flushSync call within a try...catch block to handle potential errors gracefully.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines +41 to 47
refValue.addEventListener('scroll', handleScroll, {
passive: true,
});

return () => {
handleScroll.cancel();
refValue.removeEventListener('scroll', handleScroll);
Copy link

Choose a reason for hiding this comment

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

kody code-review Kody Rules medium

let scrollEventListener = null;
const handleScroll = withThrottling({ wait: 100 })(async (event) => { /* ... */ });

scrollEventListener = handleScroll; // Store a reference to the throttled function
refValue.addEventListener('scroll', scrollEventListener, { passive: true });
// ...
return () => {
  if (scrollEventListener) {
    refValue.removeEventListener('scroll', scrollEventListener);
  }
};

While the original event listener is removed in the cleanup function, the addition of the throttled scroll listener introduces a potential issue. The handleScroll.cancel() method only cancels the throttled call, not the event listener itself. This can lead to memory leaks or unintended behavior if the component re-renders. Ensure the event listener attached to the throttled function is properly removed in the cleanup function.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

@dougfabris dougfabris changed the base branch from develop to release-7.6.0 April 25, 2025 21:10
@dougfabris dougfabris changed the base branch from release-7.6.0 to develop April 25, 2025 21:11
Copy link
Contributor

github-actions bot commented Apr 25, 2025

PR Preview Action v1.6.1

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-35880/

Built to branch gh-pages at 2025-04-28 12:23 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@dougfabris dougfabris added this to the 7.6.0 milestone Apr 25, 2025
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 36.66667% with 19 lines in your changes missing coverage. Please review.

Project coverage is 61.14%. Comparing base (71e9771) to head (bee60e1).
Report is 18 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #35880   +/-   ##
========================================
  Coverage    61.14%   61.14%           
========================================
  Files         3009     3009           
  Lines        71554    71573   +19     
  Branches     16378    16381    +3     
========================================
+ Hits         43751    43765   +14     
- Misses       24836    24842    +6     
+ Partials      2967     2966    -1     
Flag Coverage Δ
e2e 57.86% <36.66%> (+<0.01%) ⬆️
unit 75.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo ggazzo force-pushed the regression/load-more branch from 2daa7e3 to e746d93 Compare April 25, 2025 22:37
@ggazzo ggazzo marked this pull request as ready for review April 26, 2025 01:44
@ggazzo ggazzo requested a review from a team as a code owner April 26, 2025 01:44
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.

2 participants