fix: save recent emojis when selected from composer popup and fix emoji sort #40167
fix: save recent emojis when selected from composer popup and fix emoji sort #40167Naetiksoni08 wants to merge 3 commits intoRocketChat:developfrom
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
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:
WalkthroughAdds an optional Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ComposerPopupUI as "ComposerPopup UI"
participant PopupHook as "useComposerBoxPopup"
participant Provider as "ComposerPopupProvider"
participant EmojiStore as "RecentEmojiStore"
User->>ComposerPopupUI: select item
ComposerPopupUI->>PopupHook: select(item)
PopupHook->>PopupHook: perform selection logic (commands/replaceText)
PopupHook->>Provider: call option.onSelect?(item)
Provider->>EmojiStore: addRecentEmoji(item._id.slice(1, -1))
PopupHook->>ComposerPopupUI: clear popup state (setOptionIndex, setFocused)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
🧹 Nitpick comments (1)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts (1)
113-115: Ensure popup cleanup always runs even ifonSelectfails.A thrown error in
option.onSelectcan currently skip reset ofoptionIndex/focused. Wrapping callback + teardown intry/finallykeeps UI state consistent.♻️ Proposed change
- option.onSelect?.(item); - setOptionIndex(-1); - setFocused(undefined); + try { + option.onSelect?.(item); + } finally { + setOptionIndex(-1); + setFocused(undefined); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts` around lines 113 - 115, The current call to option.onSelect inside the handler can throw and prevent the cleanup calls setOptionIndex(-1) and setFocused(undefined) from running; modify the selection flow in useComposerBoxPopup so that you invoke option.onSelect(item) inside a try block and perform the cleanup (setOptionIndex(-1) and setFocused(undefined)) in a finally block to guarantee popup state reset even if option.onSelect throws. Ensure you still call option.onSelect?.(item) (guarded for undefined) and keep the final cleanup semantics intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts`:
- Around line 113-115: The current call to option.onSelect inside the handler
can throw and prevent the cleanup calls setOptionIndex(-1) and
setFocused(undefined) from running; modify the selection flow in
useComposerBoxPopup so that you invoke option.onSelect(item) inside a try block
and perform the cleanup (setOptionIndex(-1) and setFocused(undefined)) in a
finally block to guarantee popup state reset even if option.onSelect throws.
Ensure you still call option.onSelect?.(item) (guarded for undefined) and keep
the final cleanup semantics intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c006a97e-d25f-4ea5-aa72-26b7bb87e7a1
📒 Files selected for processing (3)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.tsapps/meteor/client/views/room/providers/ComposerPopupProvider.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). (1)
- GitHub Check: cubic · AI code reviewer
🧰 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/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.tsapps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
🧠 Learnings (8)
📚 Learning: 2026-04-10T22:42:03.240Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 40075
File: apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx:69-71
Timestamp: 2026-04-10T22:42:03.240Z
Learning: In `apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx`, the submit handler converts an empty/whitespace-only description to `undefined` (`description?.trim() || undefined`) intentionally. All downstream image-rendering components (`AttachmentImage`, `ImagePreview`, `ImageItem`, `ImageGallery`) default `undefined` alt to `''`, so the `<img alt="">` attribute is always present. Do not flag this `undefined` conversion as a bug preventing alt text from being cleared.
Applied to files:
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
📚 Learning: 2026-03-04T14:16:49.202Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39304
File: packages/ui-contexts/src/ActionManagerContext.ts:26-26
Timestamp: 2026-03-04T14:16:49.202Z
Learning: In `packages/ui-contexts/src/ActionManagerContext.ts` (TypeScript, RocketChat/Rocket.Chat), the `disposeView` method in `IActionManager` uses an intentionally explicit union `UiKit.ModalView['id'] | UiKit.BannerView['viewId'] | UiKit.ContextualBarView['id']` to document which view types are accepted, even though all constituents resolve to the same primitive. The inline `// eslint-disable-next-line typescript-eslint/no-duplicate-type-constituents` comment is intentional and should not be flagged or removed.
Applied to files:
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.ts
📚 Learning: 2026-03-11T22:04:20.529Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 39545
File: apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts:59-61
Timestamp: 2026-03-11T22:04:20.529Z
Learning: In `apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts`, the `msg.u._id === uid` early-return in the `streamNewMessage` handler is intentional: the "New messages" indicator is designed to notify about messages from other users only. Self-sent messages — including those sent from a different session/device — are always skipped, by design. Do not flag this as a multi-session regression.
Applied to files:
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 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/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.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/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.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/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.ts
📚 Learning: 2025-12-02T22:23:49.593Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37654
File: apps/meteor/client/hooks/useAppSlashCommands.ts:32-38
Timestamp: 2025-12-02T22:23:49.593Z
Learning: In apps/meteor/client/hooks/useAppSlashCommands.ts, the `data?.forEach((command) => slashCommands.add(command))` call during render is intentional. The query is configured with `structuralSharing: false` to prevent React Query from keeping stable data references, and `slashCommands.add` is idempotent, so executing on every render is acceptable and ensures the command registry stays current.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.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/providers/ComposerPopupProvider.tsx
🔇 Additional comments (3)
apps/meteor/client/views/room/contexts/ComposerPopupContext.ts (1)
23-23: OptionalonSelecthook is a clean, backward-compatible extension.Adding it as optional keeps existing popup configs unaffected while enabling selection side-effects in typed consumers.
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (2)
247-248: Recent-emoji tracking integration is correctly wired in both emoji popups.Hooking
onSelecttoaddRecentEmojifor both:and+:paths, plus includingaddRecentEmojiinuseMemodeps, keeps behavior consistent and closure-safe.Also applies to: 305-306, 394-394
261-263: Comparator typo fix is correct.Initializing
idBfromb._idrestores proper pairwise comparison in the+:emoji sort path.
b8459a6 to
6b3842b
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (1)
260-277:⚠️ Potential issue | 🟡 MinorFix lexicographic misordering in emoji sort comparator for 2-digit recent indexes.
Lines 265 and 268 concatenate numeric
indexOf()results with string_idvalues. In JavaScript, this triggers string concatenation (e.g.,10 + ":joy:"becomes"10:joy:"), causing incorrect lexicographic ordering where index 10 sorts before index 2.Suggested fix
- const emojiSort = (recents: string[]) => (a: { _id: string }, b: { _id: string }) => { - let idA = a._id; - let idB = b._id; - - if (recents.includes(a._id)) { - idA = recents.indexOf(a._id) + idA; - } - if (recents.includes(b._id)) { - idB = recents.indexOf(b._id) + idB; - } - - if (idA < idB) { - return -1; - } - - if (idA > idB) { - return 1; - } - - return 0; - }; + const emojiSort = (recents: string[]) => (a: { _id: string }, b: { _id: string }) => { + const rank = (id: string) => { + const index = recents.indexOf(id); + return index === -1 ? Number.MAX_SAFE_INTEGER : index; + }; + + const rankA = rank(a._id); + const rankB = rank(b._id); + + if (rankA !== rankB) { + return rankA - rankB; + } + + return a._id.localeCompare(b._id); + };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx` around lines 260 - 277, The emojiSort comparator in ComposerPopupProvider.tsx currently concatenates recents.indexOf(...) with the _id (idA/idB), causing lexicographic misordering for multi-digit indexes; instead compute a numeric recentIndex (e.g., const recentIndexA = recents.includes(a._id) ? recents.indexOf(a._id) : Infinity) and compare recentIndexA vs recentIndexB first, returning their numeric comparison if different, and only fall back to comparing a._id and b._id lexicographically when the recent indexes are equal; update the emojiSort closure (variables idA/idB, recents, comparator return path) to use this numeric-first comparison.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx`:
- Around line 260-277: The emojiSort comparator in ComposerPopupProvider.tsx
currently concatenates recents.indexOf(...) with the _id (idA/idB), causing
lexicographic misordering for multi-digit indexes; instead compute a numeric
recentIndex (e.g., const recentIndexA = recents.includes(a._id) ?
recents.indexOf(a._id) : Infinity) and compare recentIndexA vs recentIndexB
first, returning their numeric comparison if different, and only fall back to
comparing a._id and b._id lexicographically when the recent indexes are equal;
update the emojiSort closure (variables idA/idB, recents, comparator return
path) to use this numeric-first comparison.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f459aeac-0ae8-4592-a5c0-9a89128b5254
📒 Files selected for processing (3)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.tsapps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
- apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
📜 Review details
🧰 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/providers/ComposerPopupProvider.tsx
🧠 Learnings (3)
📚 Learning: 2026-03-11T22:04:20.529Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 39545
File: apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts:59-61
Timestamp: 2026-03-11T22:04:20.529Z
Learning: In `apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts`, the `msg.u._id === uid` early-return in the `streamNewMessage` handler is intentional: the "New messages" indicator is designed to notify about messages from other users only. Self-sent messages — including those sent from a different session/device — are always skipped, by design. Do not flag this as a multi-session regression.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2025-12-02T22:23:49.593Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37654
File: apps/meteor/client/hooks/useAppSlashCommands.ts:32-38
Timestamp: 2025-12-02T22:23:49.593Z
Learning: In apps/meteor/client/hooks/useAppSlashCommands.ts, the `data?.forEach((command) => slashCommands.add(command))` call during render is intentional. The query is configured with `structuralSharing: false` to prevent React Query from keeping stable data references, and `slashCommands.add` is idempotent, so executing on every render is acceptable and ensures the command registry stays current.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.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/providers/ComposerPopupProvider.tsx
🔇 Additional comments (3)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (3)
187-187: Whitespace-only JSX formatting change.No functional impact.
31-31: Good integration of emoji-recents callback into memoized config.Line 88 correctly consumes
addRecentEmoji, and Line 394 includes it in theuseMemodeps, avoiding stale callback capture.Also applies to: 88-88, 394-394
247-247: Selection side-effect wiring looks correct for both emoji triggers.Using
item._id.slice(1, -1)passes the unwrapped emoji id expected byaddRecentEmoji, so both:and+:flows now persist recents.Also applies to: 305-305
6b3842b to
198e159
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (1)
260-280: Consider unifying the twoemojiSortimplementations.With
idBfixed, this sort now runs, but the string-concatenation approach is fragile and inconsistent with the score-basedemojiSortin the:block above (lines 199–222):
- Multi-digit recent indices sort lexicographically — e.g., index
"10"prefixes come before"2"prefixes ('1' < '2'), so a less-recent entry can bubble above a more-recent one once recents grow beyond 10.- Non-recent items fall back to plain
_idalphabetical order with no exact/prefix weighting againstkey, unlike the:variant.Aligning both blocks on the score-based comparator (and extracting the duplicated
getItemsFromLocalbody) would fix the ordering edge case and remove ~40 lines of duplication.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx` around lines 260 - 280, The two emojiSort implementations are inconsistent and fragile (string-concatenation causes lexicographic bugs); refactor by replacing the second emojiSort with the same score-based comparator used by the first one: compute a numeric score for each item using recents.indexOf(id) (with non-recents given a large sentinel like Infinity or -1 handled consistently) plus a secondary tie-breaker of _id or key, then compare those numeric scores instead of concatenating strings; also extract the duplicated getItemsFromLocal logic into a single helper used by both the ':' and emoji branches to remove ~40 lines of duplication and ensure both branches use the same ordering logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx`:
- Line 88: ComposerPopupProvider currently calls useEmojiPickerData() (which
calls useEmojiPickerContext() and throws if missing) unconditionally; change it
so ComposerPopupProvider no longer crashes when EmojiPickerProvider is absent by
either using a non-throwing accessor or guarding the call: implement or use an
optional hook (e.g., useOptionalEmojiPickerContext or modify useEmojiPickerData
to return null/noop when context is missing) and only call addRecentEmoji when
the context exists, or wrap the component with EmojiPickerProvider at the top
level; update references to useEmojiPickerData, useEmojiPickerContext,
ComposerPopupProvider, and addRecentEmoji accordingly so the provider absence is
handled safely.
---
Nitpick comments:
In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx`:
- Around line 260-280: The two emojiSort implementations are inconsistent and
fragile (string-concatenation causes lexicographic bugs); refactor by replacing
the second emojiSort with the same score-based comparator used by the first one:
compute a numeric score for each item using recents.indexOf(id) (with
non-recents given a large sentinel like Infinity or -1 handled consistently)
plus a secondary tie-breaker of _id or key, then compare those numeric scores
instead of concatenating strings; also extract the duplicated getItemsFromLocal
logic into a single helper used by both the ':' and emoji branches to remove ~40
lines of duplication and ensure both branches use the same ordering logic.
🪄 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: 0612f046-701a-4bc5-9e84-61b6723530bd
📒 Files selected for processing (3)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.tsapps/meteor/client/views/room/contexts/ComposerPopupContext.tsapps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
✅ Files skipped from review due to trivial changes (1)
- apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
📜 Review details
🧰 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/providers/ComposerPopupProvider.tsx
🧠 Learnings (3)
📚 Learning: 2026-03-11T22:04:20.529Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 39545
File: apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts:59-61
Timestamp: 2026-03-11T22:04:20.529Z
Learning: In `apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts`, the `msg.u._id === uid` early-return in the `streamNewMessage` handler is intentional: the "New messages" indicator is designed to notify about messages from other users only. Self-sent messages — including those sent from a different session/device — are always skipped, by design. Do not flag this as a multi-session regression.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2025-12-02T22:23:49.593Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37654
File: apps/meteor/client/hooks/useAppSlashCommands.ts:32-38
Timestamp: 2025-12-02T22:23:49.593Z
Learning: In apps/meteor/client/hooks/useAppSlashCommands.ts, the `data?.forEach((command) => slashCommands.add(command))` call during render is intentional. The query is configured with `structuralSharing: false` to prevent React Query from keeping stable data references, and `slashCommands.add` is idempotent, so executing on every render is acceptable and ensures the command registry stays current.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.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/providers/ComposerPopupProvider.tsx
🔇 Additional comments (1)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (1)
262-262: Good catch on the comparator fix.Setting
idB = b._id(previouslya._id) makes the\+:reaction popup comparator actually meaningful — the prior self-comparison always produced0and left ordering undefined.
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx">
<violation number="1" location="apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx:210">
P2: Recent emojis are scored backwards in the `:` popup, so older recents can sort above newer ones and even outrank exact matches.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (1)
267-287:⚠️ Potential issue | 🟡 Minor
+:sort: fix is correct, but the comparator is still fragile and inconsistent with the:popup.The
idB = b._idfix resolves the self-comparison bug. However, two concerns remain in this comparator:
- Numeric-as-string ordering breaks at 10+ recents.
recents.indexOf(a._id) + idAprepends the index as a string; lexicographic compare gives"10:smile:" < "2:smile:", so onceemoji.recentgrows to 10+ matching entries, recent-order is wrong. Consider pinning the recent check as a primary comparator returning numeric indices directly.- Match quality is ignored. Unlike the new
:popup (lines 200–229) which scores exact/prefix matches first, this comparator sorts by raw_id(with the index-prefix hack). The two popups will now order similar candidate sets differently for the same filter.Consider reusing the same
emojiSorthelper for both popups so behavior stays consistent.♻️ Example: reuse the `:` popup comparator
- const emojiSort = (recents: string[]) => (a: { _id: string }, b: { _id: string }) => { - let idA = a._id; - let idB = b._id; - - if (recents.includes(a._id)) { - idA = recents.indexOf(a._id) + idA; - } - if (recents.includes(b._id)) { - idB = recents.indexOf(b._id) + idB; - } - - if (idA < idB) { - return -1; - } - - if (idA > idB) { - return 1; - } - - return 0; - }; + const emojiSort = (recents: string[]) => (a: { _id: string }, b: { _id: string }) => { + const aExact = a._id === key ? 2 : 0; + const bExact = b._id === key ? 2 : 0; + const aPartial = a._id.startsWith(key) ? 1 : 0; + const bPartial = b._id.startsWith(key) ? 1 : 0; + const aScore = aExact + aPartial; + const bScore = bExact + bPartial; + if (aScore !== bScore) return bScore - aScore; + const aRecent = recents.indexOf(a._id); + const bRecent = recents.indexOf(b._id); + if (aRecent === bRecent) return 0; + if (aRecent === -1) return 1; + if (bRecent === -1) return -1; + return aRecent - bRecent; + };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx` around lines 267 - 287, The comparator emojiSort currently builds string prefixes and does lexicographic compares which breaks when recents length >=10 and ignores match quality; change emojiSort to return a numeric comparison: first compute recent indices for a and b (use -1 when not found) and return compare(recIndexA, recIndexB) if indices differ (treat found<not found), then reuse the same match-quality scoring used by the ":" popup (the scoring routine from the popup comparator at lines ~200–229) to compare exact/prefix matches, and finally fall back to comparing the raw _id strings; consider extracting that scoring logic into a shared helper and have both popups call it so ordering is consistent across both emoji popups.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx`:
- Around line 267-287: The comparator emojiSort currently builds string prefixes
and does lexicographic compares which breaks when recents length >=10 and
ignores match quality; change emojiSort to return a numeric comparison: first
compute recent indices for a and b (use -1 when not found) and return
compare(recIndexA, recIndexB) if indices differ (treat found<not found), then
reuse the same match-quality scoring used by the ":" popup (the scoring routine
from the popup comparator at lines ~200–229) to compare exact/prefix matches,
and finally fall back to comparing the raw _id strings; consider extracting that
scoring logic into a shared helper and have both popups call it so ordering is
consistent across both emoji popups.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0c57b3de-d0b0-4be4-8271-496101ccd68c
📒 Files selected for processing (1)
apps/meteor/client/views/room/providers/ComposerPopupProvider.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). (1)
- GitHub Check: cubic · AI code reviewer
🧰 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/providers/ComposerPopupProvider.tsx
🧠 Learnings (13)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-03-04T14:16:49.202Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39304
File: packages/ui-contexts/src/ActionManagerContext.ts:26-26
Timestamp: 2026-03-04T14:16:49.202Z
Learning: In `packages/ui-contexts/src/ActionManagerContext.ts` (TypeScript, RocketChat/Rocket.Chat), the `disposeView` method in `IActionManager` uses an intentionally explicit union `UiKit.ModalView['id'] | UiKit.BannerView['viewId'] | UiKit.ContextualBarView['id']` to document which view types are accepted, even though all constituents resolve to the same primitive. The inline `// eslint-disable-next-line typescript-eslint/no-duplicate-type-constituents` comment is intentional and should not be flagged or removed.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-03-20T13:51:23.302Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 39553
File: apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts:179-181
Timestamp: 2026-03-20T13:51:23.302Z
Learning: In `apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts`, the truthiness guards `...(integration.avatar && { avatar })`, `...(integration.emoji && { emoji })`, `...(integration.alias && { alias })`, and `...(integration.script && { script })` in the `$set` payload of `updateIncomingIntegration` are intentional. Empty-string values for these fields should NOT overwrite the stored value — only truthy values are persisted. Do not flag these as bugs preventing explicit clears.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-03-06T18:10:23.330Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:23.330Z
Learning: In the RocketChat/Rocket.Chat `packages/gazzodown` package and more broadly, the HTML `<code>` element has an implicit ARIA role of `code` per WAI-ARIA 1.3, and `testing-library/dom` / jsdom supports it. Therefore, `screen.getByRole('code')` / `screen.findByRole('code')` correctly locates `<code>` elements without needing an explicit `role="code"` attribute. Do NOT flag `findByRole('code')` as invalid in future reviews.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-04-10T22:42:05.539Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 40075
File: apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx:69-71
Timestamp: 2026-04-10T22:42:05.539Z
Learning: In `apps/meteor/client/views/room/modals/FileUploadModal/FileUploadModal.tsx`, the submit handler converts an empty/whitespace-only description to `undefined` (`description?.trim() || undefined`) intentionally. All downstream image-rendering components (`AttachmentImage`, `ImagePreview`, `ImageItem`, `ImageGallery`) default `undefined` alt to `''`, so the `<img alt="">` attribute is always present. Do not flag this `undefined` conversion as a bug preventing alt text from being cleared.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.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/providers/ComposerPopupProvider.tsx
📚 Learning: 2025-12-02T22:23:49.593Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37654
File: apps/meteor/client/hooks/useAppSlashCommands.ts:32-38
Timestamp: 2025-12-02T22:23:49.593Z
Learning: In apps/meteor/client/hooks/useAppSlashCommands.ts, the `data?.forEach((command) => slashCommands.add(command))` call during render is intentional. The query is configured with `structuralSharing: false` to prevent React Query from keeping stable data references, and `slashCommands.add` is idempotent, so executing on every render is acceptable and ensures the command registry stays current.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-04-14T21:10:36.233Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 36292
File: apps/meteor/client/hooks/useHasValidLocationHash.ts:7-12
Timestamp: 2026-04-14T21:10:36.233Z
Learning: In the RocketChat/Rocket.Chat repository, adding JSDoc-style comments to React hooks (e.g., files under apps/meteor/client/hooks/) is considered a good pattern and should not be flagged as a violation of the "avoid code comments in the implementation" guideline. The guideline against code comments does not apply to JSDoc documentation on exported hooks.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-01-19T18:08:13.423Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38169
File: packages/ui-client/src/hooks/useGoToDirectMessage.ts:20-27
Timestamp: 2026-01-19T18:08:13.423Z
Learning: In React hooks, including custom hooks like useUserSubscriptionByName, must always be called unconditionally and in the same order on every render, per the Rules of Hooks. Passing empty strings or fallback values to hooks is the correct approach when dealing with potentially undefined values, rather than conditionally calling the hook based on whether the value exists.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-04-13T16:40:55.864Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 40100
File: apps/meteor/client/views/root/MainLayout/EmbeddedPreload.tsx:18-35
Timestamp: 2026-04-13T16:40:55.864Z
Learning: In Rocket.Chat's embedded mode (`?layout=embedded`), route changes are driven by the parent frame reloading the iframe URL, which causes a full remount of the React tree (including `EmbeddedPreload` at `apps/meteor/client/views/root/MainLayout/EmbeddedPreload.tsx`). The component never survives a navigation, so `roomParams` (computed via `useMemo`) is always fresh on mount. A `[router]` singleton as the sole `useMemo` dependency is therefore correct and intentional — do not flag it as a stale-dependency bug in this component.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.
Applied to files:
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
🔇 Additional comments (3)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (3)
88-89: Safe fallback for missingEmojiPickerProvider— LGTM.Using
useContext(EmojiPickerContext)directly with?? (() => undefined)correctly prevents crashes when the provider is absent (tests, Storybook, embedded surfaces). Matches the pattern agreed in the previous review.
200-254::popup: new match-quality sort + recent wiring looks correct.Score-first ordering (exact > prefix > other) with a recency tiebreaker is an improvement over the previous index-concatenation approach, and the
onSelect: (item) => addRecentEmoji(item._id.slice(1, -1))correctly strips the surrounding:before persisting toemoji.recent(matches the localStorage screenshot in the PR description).
312-312: Recording recent emoji on+:selection — LGTM.Mirrors the
:popup wiring and produces the unprefixed shortcode expected byaddRecentEmoji.
5ca8362 to
ec5c9fa
Compare
Proposed changes (including videos or screenshots)
Two related bugs were found and fixed in the emoji composer popup:
Bug 1 — Recent emojis never saved from composer popup
When a user selected an emoji using the
:or+:trigger in the message composer,addRecentEmojiwas never called. This meantemoji.recentin localStorage was never populated, so the "recently used" sorting had no data to work with.Fix: Added an
onSelectcallback toComposerPopupOptiontype and wired it up in both emoji popup configs to calladdRecentEmojion selection.Bug 2 — Broken sort in
+:emoji reaction popupIn the
emojiSortfunction for the+:trigger,idBwas incorrectly assigneda._idinstead ofb._id, causing every comparison to return0(equal) andmaking the sort completely ineffective.
Before Fix: Recently used emojis never appeared at the top. Order was random.
And because of this
emoji.recentin localStorage was never populatedAfter Fix: Recently used emojis correctly appear at the top of the popup.
And now this
emoji.recentin localStorage is populated correctlySteps to test or reproduce
Further comments
The root cause was that the composer popup had no mechanism to notify the emoji system when an emoji was selected. The fix adds an optional onSelect callback to ComposerPopupOption which is generic enough to be used by other popup types in the future if needed.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor