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 1 commit 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 |
|
WalkthroughThe changes add a selection callback mechanism to composer popup options and integrate it with emoji recent history tracking. A logic bug in the emoji sorting comparator is also fixed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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.
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
Release Notes
New Features
Bug Fixes