Skip to content

fix: save recent emojis when selected from composer popup and fix emoji sort #40167

Open
Naetiksoni08 wants to merge 1 commit intoRocketChat:developfrom
Naetiksoni08:fix/emoji-sort-idB-typo
Open

fix: save recent emojis when selected from composer popup and fix emoji sort #40167
Naetiksoni08 wants to merge 1 commit intoRocketChat:developfrom
Naetiksoni08:fix/emoji-sort-idB-typo

Conversation

@Naetiksoni08
Copy link
Copy Markdown
Contributor

@Naetiksoni08 Naetiksoni08 commented Apr 15, 2026

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, addRecentEmoji was never called. This meant emoji.recent in localStorage was never populated, so the "recently used" sorting had no data to work with.

Fix: Added an onSelect callback to ComposerPopupOption type and wired it up in both emoji popup configs to call addRecentEmoji on selection.

Bug 2 — Broken sort in +: emoji reaction popup

In the emojiSort function for the +: trigger, idB was incorrectly assigned a._id instead of b._id, causing every comparison to return 0 (equal) and
making the sort completely ineffective.

// Before (broken)
let idA = a._id;                                                                                                                                                
let idB = a._id; // ← always comparing a against itself
                                                                                                                                                                
// After (fixed)
let idA = a._id;                                                                                                                                                
let idB = b._id;

Before Fix: Recently used emojis never appeared at the top. Order was random.

Screenshot 2026-04-15 at 2 15 15 PM Screenshot 2026-04-15 at 2 11 45 PM

And because of this emoji.recent in localStorage was never populated

After Fix: Recently used emojis correctly appear at the top of the popup.

Screenshot 2026-04-15 at 2 15 15 PM Screenshot 2026-04-15 at 2 16 16 PM

And now this emoji.recent in localStorage is populated correctly

Screenshot 2026-04-15 at 2 17 31 PM

Steps to test or reproduce

  1. Open any room or DM
  2. Type smirk: in the composer and select it from the popup to send
  3. Now type +:smi in the composer
  4. Before fix: smirk: does not appear at the top
  5. After fix: smirk: appears at the top as a recently used emoji

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

    • Emoji picker now maintains a history of recently selected emojis, allowing faster access to frequently used emojis during message composition.
  • Bug Fixes

    • Fixed sorting logic error in emoji selection popup that caused incorrect ordering of emoji options.

@Naetiksoni08 Naetiksoni08 requested a review from a team as a code owner April 15, 2026 09:15
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Apr 15, 2026

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

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

⚠️ No Changeset found

Latest commit: b8459a6

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

Walkthrough

The 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

Cohort / File(s) Summary
Selection Callback Infrastructure
apps/meteor/client/views/room/contexts/ComposerPopupContext.ts, apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
Added optional onSelect callback to the ComposerPopupOption type and wired it to invoke after item selection in the popup hook, before clearing internal state.
Emoji Recent History Integration
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
Integrated emoji tracking by importing useEmojiPickerData, deriving addRecentEmoji, and adding onSelect handlers to two emoji popup configurations to update recent emojis. Fixed emoji sorting comparator logic bug where idB was incorrectly initialized from a._id instead of b._id.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes both main changes: saving recent emojis when selected from the composer popup and fixing the emoji sort bug.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts (1)

113-115: Ensure popup cleanup always runs even if onSelect fails.

A thrown error in option.onSelect can currently skip reset of optionIndex/focused. Wrapping callback + teardown in try/finally keeps 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

📥 Commits

Reviewing files that changed from the base of the PR and between 41f6662 and b8459a6.

📒 Files selected for processing (3)
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • 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/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/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.ts
  • apps/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.ts
  • apps/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.ts
  • apps/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.ts
  • apps/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.ts
  • apps/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: Optional onSelect hook 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 onSelect to addRecentEmoji for both : and +: paths, plus including addRecentEmoji in useMemo deps, keeps behavior consistent and closure-safe.

Also applies to: 305-306, 394-394


261-263: Comparator typo fix is correct.

Initializing idB from b._id restores proper pairwise comparison in the +: emoji sort path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant