Skip to content

fix: message list loads the entire room history while hidden - #41787

Closed
ndo84bw wants to merge 2 commits into
RocketChat:release-8.8.0from
ndo84bw:fix/message-list-history-loop-while-hidden
Closed

fix: message list loads the entire room history while hidden#41787
ndo84bw wants to merge 2 commits into
RocketChat:release-8.8.0from
ndo84bw:fix/message-list-history-loop-while-hidden

Conversation

@ndo84bw

@ndo84bw ndo84bw commented Aug 14, 2026

Copy link
Copy Markdown

Proposed changes (including videos or screenshots)

RoomLayout hides the entire message body with display: none once a contextual bar takes the full room width, which happens below 600px of room width - not viewport width, since the breakpoints come from a ResizeObserver on the room element:

const contextualbarSize = breakpoints.includes('sm') ? (breakpoints.includes('xl') ? '38%' : '380px') : '100%';
const hideBody = aside && contextualbarSize === '100%';

A hidden element reports clientHeight and scrollTop as 0, so the load-older-messages check in
useGetMore is permanently true:

const { scrollTop, clientHeight, scrollHeight } = getBoundingClientRect(element);
...
if (hasMore === true && lastScrollTopRef <= height / 3) {   // 0 <= 0 / 3
    await RoomHistoryManager.getMore(rid);

The MutationObserver and ResizeObserver attached to that same element then drive the loading themselves: every page that arrives mutates the DOM, the observer fires, the next page loads.
Nothing stops it until the room has no history left. The client pulls the whole room 50 messages at a time and runs into the DDP rate limiter - the tail of the request list is loadHistory returning HTTP 400 too-many-requests.

RoomHistoryManager.restoreScroll cannot compensate, because it measures scrollHeight on the same hidden element and gets 0 - 0 as the height difference. So when the panel closes, the scroll offset is unchanged while the list is several times taller, and the user is left far in the past.

This PR bails out when the list is not rendered, and adds a unit test for it.

Before - one pixel narrower, thread opened, nobody scrolling: a stream of loadHistory calls
ending in HTTP 400, and the list is far up when the thread closes.

2026-08-14-nachladeschleife-880-vs-879-develop.mp4

After - same steps: 5 requests for the whole open-wait-close cycle (because scroll in thread), none of them
loadHistory, and the list stays where it was.

2026-08-14-nach-fix-879-develop.mp4

Control at 1220px room width: list height unchanged in both cases, no jump - so the trigger is the
hidden body, not opening a panel as such.

Issue(s)

Fixes #41132

Related to #41159, which addresses a different threshold - see Further comments.

Steps to test or reproduce

Four conditions have to hold at once, and two of them are easy to destroy by accident, which is
probably why this has looked flaky:

  1. hasMore must still be true - reload the page first. Once a room's history has been fully
    pulled in a session, that room is immune for the rest of the session.
  2. userInteracted must be true - scroll the main list once with the wheel, or click in it. The
    flag is a per-mount closure variable and resets on every room switch.
  3. The room area must be under 600px with a thread open, so the body is hidden.
  4. The list must not be at the very bottom - scroll up a little first. At the bottom the
    virtualizer keeps the list anchored there and the growth stays invisible.

Then:

  1. Narrow the window until the thread view takes the full chat width. With a default sidebar the
    threshold sits exactly between 880px and 879px of window width:
    window room area message body
    880px 600px visible
    879px 599px hidden
  2. Reload.
  3. Open a room with a few thousand messages spanning a long period, so the jump is visible by date.
  4. Scroll the main list up a little with the wheel.
  5. Open a thread from the message list.
  6. Wait 20-30 seconds with the window in the foreground, watching the network panel.
  7. Close the thread.

Sanity checks that should not trigger it: a wide window, closing the thread again within a
second, a second attempt without reloading, or opening the thread from the Threads contextual bar
without touching the main list first.

Tested on 8.8.0-develop at 02e633cf27 and on 8.6.1 at bfd782302d, in a room with 5162
messages spanning five years and a thread with 60 replies, at 580px room width.

Further comments

The guard reads the clientHeight that getBoundingClientRect already returned rather than asking
the element again. That is the exact value the position check uses, and it keeps the hook testable:
jsdom performs no layout and reports 0 for every element, so a guard reading element.clientHeight
directly would make the two existing tests in useGetMore.spec.tsx fail.

Alternatives considered:

  • Guarding inside gatedCheck so only observer-driven calls are skipped. That leaves the same
    always-true condition in place for any other caller, and a hidden element cannot emit a scroll
    event anyway, so the guard belongs where the value is read.
  • Not observing the element at all while it is hidden. That is more code for the same effect and
    would need the layout state threaded into this hook.
  • Removing hideBody so the situation cannot arise. That is what fix: prevent scroll jump when closing thread in narrow layout #41159 approaches from the layout
    side, but the 0 <= 0 fragility would remain for any other case that hides the list.

On #41159: it takes the aside out of the flex flow, which addresses a different threshold. Between
600px and 768px of room width the body is not hidden but squeezed - at 600px room width the message
list drops to 220px, text rewraps, cached row heights go stale, and the scroll position is off by a
noticeable amount when the panel closes. That is a separate defect with its own trigger; this change
does not touch that path and does not conflict with it, and the hideBody branch below 600px stays
as it is.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Prevented hidden message lists from incorrectly loading older messages when their container has no visible height.
    • Fixed rooms from loading excessive history and leaving the message list scrolled far into the past after closing a full-width contextual bar.

@ndo84bw
ndo84bw requested a review from a team as a code owner August 14, 2026 08:52
@dionisio-bot

dionisio-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fba9afa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b722874c-74e6-4f55-8550-6211d92aef61

📥 Commits

Reviewing files that changed from the base of the PR and between 6a5456e and 5f74bb0.

📒 Files selected for processing (3)
  • .changeset/soft-poems-shave.md
  • apps/meteor/client/views/room/body/hooks/useGetMore.spec.tsx
  • apps/meteor/client/views/room/body/hooks/useGetMore.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/meteor/client/views/room/body/hooks/useGetMore.ts
  • apps/meteor/client/views/room/body/hooks/useGetMore.spec.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
🔇 Additional comments (1)
.changeset/soft-poems-shave.md (1)

1-6: LGTM!


Walkthrough

The message history loader now ignores zero-height message containers. A regression test verifies that hidden containers do not request older messages. A patch changeset documents the scroll-position fix.

Changes

Hidden message pagination

Layer / File(s) Summary
Zero-height pagination guard
apps/meteor/client/views/room/body/hooks/useGetMore.ts, apps/meteor/client/views/room/body/hooks/useGetMore.spec.tsx, .changeset/soft-poems-shave.md
checkPositionAndGetMore returns when the message container has zero height. The asynchronous regression test verifies that RoomHistoryManager.getMore is not called. The changeset documents the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5f74b

This localized change prevents hidden message lists from automatically loading room history and includes a focused unit test; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary fix: preventing message history from loading while the message list is hidden.
Linked Issues check ✅ Passed The guard and regression test address issue #41132 by preventing hidden message lists from loading history and changing scroll position.
Out of Scope Changes check ✅ Passed The hook change, regression test, and patch changeset are directly related to the linked issue and stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • A895A78D-7135: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot 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 issues found across 3 files

Re-trigger cubic

`RoomLayout` hides the whole message body with `display: none` once a
contextual bar takes the full room width, which happens below 600px of room
width. A hidden element reports `clientHeight` and `scrollTop` as 0, so the
position check in `useGetMore`, `scrollTop <= clientHeight / 3`, is
permanently true.

The MutationObserver and ResizeObserver on that same element then drive the
loading themselves: each loaded page mutates the DOM, the observer fires, the
next page loads. Nothing stops it until the room has no history left. On a
room with a few thousand messages the client pulls all of them, 50 at a time,
and runs into the DDP rate limiter.

`RoomHistoryManager.restoreScroll` cannot compensate either, because it
measures `scrollHeight` on the same hidden element and gets `0 - 0` as the
height difference. So when the panel closes, the scroll offset is unchanged
while the list is several times taller, and the user is left far in the past.

Bail out when the list is not rendered. The guard reads the `clientHeight`
that `getBoundingClientRect` already returned rather than the element again,
so it is the exact value the check uses, and it stays testable: jsdom performs
no layout and reports 0 for every element.

Measured on a room with 5162 messages at 580px room width: the list grew from
2738px to 29018px within 30 seconds of having a thread open; with this guard
it stays at 2738px and no `loadHistory` call is made at all.

Assisted-by: claude-code:claude-opus-5
@ricardogarim
ricardogarim changed the base branch from develop to release-8.8.0 August 21, 2026 16:55
@ricardogarim
ricardogarim force-pushed the fix/message-list-history-loop-while-hidden branch from 3f92dfb to 5f74bb0 Compare August 21, 2026 17:00
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@ricardogarim

ricardogarim commented Aug 21, 2026

Copy link
Copy Markdown
Member

Hey @ndo84bw, thanks for the contribution! The fix is valid. I also added a few minor adjustments and just asked the team to review.

For the internal controls, the ticket is SUP-1104.

RC team: Just a reminder that we need to include this in 8.8 and then backport it to the previous affected versions, since this issue has been happening since 8.5, IIRC.

@ricardogarim ricardogarim added this to the 8.8.0 milestone Aug 21, 2026
@ricardogarim
ricardogarim force-pushed the fix/message-list-history-loop-while-hidden branch from 5f74bb0 to fba9afa Compare August 21, 2026 17:11
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-8.8.0@6a5456e). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##             release-8.8.0   #41787   +/-   ##
================================================
  Coverage                 ?   69.34%           
================================================
  Files                    ?     4255           
  Lines                    ?   168665           
  Branches                 ?    30073           
================================================
  Hits                     ?   116953           
  Misses                   ?    46535           
  Partials                 ?     5177           
Flag Coverage Δ
e2e 58.81% <100.00%> (?)
e2e-api 45.86% <ø> (?)
unit 71.27% <100.00%> (?)

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.

@jessicaschelly jessicaschelly added the stat: QA assured Means it has been tested and approved by a company insider label Aug 21, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 21, 2026
@ricardogarim

Copy link
Copy Markdown
Member

We’ll move forward with #41454, which was opened earlier. Anyway, thanks for the contribution!

@alfredodelfabro alfredodelfabro removed this from the 8.8.0 milestone Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread close scrolls main chat back after opening thread in narrow responsive layout

4 participants