regression: Message list not staying at the bottom#40755
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
WalkthroughAdds a ResizeObserver-based hook (useKeepAtBottom) and wires it into MessageList, RoomBody, and ThreadMessageList to register a scroll-to-end callback, include the hook's ref in merged refs, and adjust bottom-detection logic. ChangesKeep-at-Bottom Virtualization
sequenceDiagram
participant ResizeObserver
participant Hook as useKeepAtBottom
participant RoomBody
participant MessageList
participant Virtua as VirtuaVirtualizer
ResizeObserver->>Hook: container/child size change
Hook->>Hook: check isAtBottom.current
Hook->>RoomBody: call stored setKeepAtBottom handler
RoomBody->>MessageList: registered callback invoked
MessageList->>Virtua: scrollToIndex(messagesLength, align:'end')
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts (2)
44-46: ⚡ Quick win
setKeepAtBottomparameter type is misleading.
handle: () => void | nullparses as a function returningvoid | null, not a nullable handler. GivenhandleRefis(() => void) | null, the intended type is(() => void) | null(or simply() => void, matching theMessageListProps.setKeepAtBottomcontract).♻️ Proposed fix
- const setKeepAtBottom = useCallback((handle: () => void | null) => { + const setKeepAtBottom = useCallback((handle: () => void) => { handleRef.current = handle; }, []);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts` around lines 44 - 46, The parameter type for setKeepAtBottom is incorrect: change the parameter from a function-typed return signature to a nullable handler type to match handleRef and the MessageListProps.setKeepAtBottom contract; update the setKeepAtBottom signature so its parameter is (() => void) | null (or simply () => void if non-nullable) and assign that value to handleRef.current inside the useCallback to ensure types align with handleRef and the external prop.
8-15: 💤 Low valueExplanatory comment block conflicts with the no-comments guideline.
Consider moving this rationale into a PR/commit note or condensing it. As per coding guidelines: "Avoid code comments in the implementation".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts` around lines 8 - 15, The large explanatory comment block at the top of useKeepAtBottom.ts conflicts with the "no-comments" guideline; remove or relocate this rationale to the PR/commit description and keep the source file minimal. In practice, delete the multi-line block in the file containing the useKeepAtBottom hook, leaving at most a single-line comment or JSDoc summary if absolutely necessary, and ensure the remaining code and function name useKeepAtBottom remain unchanged and fully documented in the commit/PR message instead.apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx (1)
211-216: ⚡ Quick winDead assignment in
onScroll— theifblock is immediately overwritten.
isAtBottom.current = true(Line 214) is unconditionally overwritten by Line 216 on every call, so the block has no effect. The short-content case is already covered by the offset formula: whenscrollSize <= viewportSize,offsetis0and0 - scrollSize + viewportSize >= -20istrue. Drop the dead block (and its comment, per the no-comments guideline) for clarity.As per coding guidelines: "Avoid code comments in the implementation".♻️ Proposed fix
const handle = virtualizerRef.current; if (!handle) return; - - // Copied from messageList, I'm unsure why this is necessary, but it seems to be needed to properly set the isAtBottom state - if (handle.scrollSize >= handle.viewportSize) { - isAtBottom.current = true; - } isAtBottom.current = offset - handle.scrollSize + handle.viewportSize >= -20;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx` around lines 211 - 216, Remove the dead assignment in the onScroll handler: the conditional that sets isAtBottom.current = true (which references handle.scrollSize and handle.viewportSize) is immediately overwritten by the subsequent calculation using offset, so delete that if block and its comment; keep the existing calculation isAtBottom.current = offset - handle.scrollSize + handle.viewportSize >= -20 to determine bottom state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts`:
- Around line 22-34: The code uses node.firstChild and then calls
observer.observe(node.firstChild as HTMLElement), which can throw if firstChild
is a non-Element; update useKeepAtBottom.ts to use node.firstElementChild (or
otherwise guard for Element) when assigning listWrapper and before calling
ResizeObserver.observe, e.g. ensure listWrapper is an Element (check truthiness
and instanceof Element) and call observer.observe(listWrapper) instead of
observing a possibly-text node; keep the existing logic around observer,
sizeChanged, isAtBottom.current, and handleRef.current unchanged.
- Around line 18-29: In useKeepAtBottom, the contentRectRef guard is never
updated so sizeChanged(contentRectRef.current, entry.contentRect) is always
true; fix by updating contentRectRef when the ResizeObserver fires (e.g., set
contentRectRef.current = entry.contentRect or maintain a Map of target->rect if
observing multiple elements) and then run the sizeChanged check against the
previous rect before overwriting, so handleRef.current() only fires when a real
size change is detected; update the ResizeObserver callback inside
useKeepAtBottom (referencing contentRectRef, sizeChanged, isAtBottom, handleRef)
accordingly or alternatively remove the unused guard if you opt not to track
previous rects.
In `@apps/meteor/client/views/room/MessageList/MessageList.tsx`:
- Around line 84-94: The keep-at-bottom logic uses
virtualizerRef.current.scrollToIndex(messagesLength, ...) which can target one
past the last rendered item when canPreview is true; change the index passed to
scrollToIndex to messagesLength - 1 so it always targets the last rendered item
(use the existing messagesLength value, subtract 1) inside the setKeepAtBottom
effect that references virtualizerRef and setKeepAtBottom, keeping the align:
'end' behavior unchanged.
---
Nitpick comments:
In
`@apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx`:
- Around line 211-216: Remove the dead assignment in the onScroll handler: the
conditional that sets isAtBottom.current = true (which references
handle.scrollSize and handle.viewportSize) is immediately overwritten by the
subsequent calculation using offset, so delete that if block and its comment;
keep the existing calculation isAtBottom.current = offset - handle.scrollSize +
handle.viewportSize >= -20 to determine bottom state.
In `@apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts`:
- Around line 44-46: The parameter type for setKeepAtBottom is incorrect: change
the parameter from a function-typed return signature to a nullable handler type
to match handleRef and the MessageListProps.setKeepAtBottom contract; update the
setKeepAtBottom signature so its parameter is (() => void) | null (or simply ()
=> void if non-nullable) and assign that value to handleRef.current inside the
useCallback to ensure types align with handleRef and the external prop.
- Around line 8-15: The large explanatory comment block at the top of
useKeepAtBottom.ts conflicts with the "no-comments" guideline; remove or
relocate this rationale to the PR/commit description and keep the source file
minimal. In practice, delete the multi-line block in the file containing the
useKeepAtBottom hook, leaving at most a single-line comment or JSDoc summary if
absolutely necessary, and ensure the remaining code and function name
useKeepAtBottom remain unchanged and fully documented in the commit/PR message
instead.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 077c80fb-7099-492c-aa43-4f5af54d8bf7
📒 Files selected for processing (4)
apps/meteor/client/views/room/MessageList/MessageList.tsxapps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.tsapps/meteor/client/views/room/body/RoomBody.tsxapps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.tsapps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsxapps/meteor/client/views/room/body/RoomBody.tsxapps/meteor/client/views/room/MessageList/MessageList.tsx
🧠 Learnings (6)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.
Applied to files:
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.
Applied to files:
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.tsapps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsxapps/meteor/client/views/room/body/RoomBody.tsxapps/meteor/client/views/room/MessageList/MessageList.tsx
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.
Applied to files:
apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsxapps/meteor/client/views/room/body/RoomBody.tsxapps/meteor/client/views/room/MessageList/MessageList.tsx
🔇 Additional comments (2)
apps/meteor/client/views/room/body/RoomBody.tsx (1)
113-115: LGTM!Also applies to: 228-228
apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx (1)
80-92: LGTM!Also applies to: 199-199
There was a problem hiding this comment.
1 issue found across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
MartinSchoeler
left a comment
There was a problem hiding this comment.
Not working with jump to messages that need loading (older messages)
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release-8.5.0 #40755 +/- ##
================================================
Coverage ? 69.97%
================================================
Files ? 3328
Lines ? 126624
Branches ? 21998
================================================
Hits ? 88602
Misses ? 34730
Partials ? 3292
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
We tested and there was an issue with the logic that flags if the list is at the bottom (already fixed, thanks!), which would cause some issues when all messages were not loaded, but we discovered that this was not a cause for the issues happening with "jump to messages".
Proposed changes (including videos or screenshots)
The fix is pretty simple: Observe both the list wrapper and its container, if the list is flagged as currently at the bottom, keep it there if any size changes.
Issue(s)
CORE-2216
Steps to test or reproduce
Further comments
Summary by CodeRabbit