Skip to content

fix: standardize IEmoji types and remove unsafe emoji casts - #41275

Open
Jbansal2 wants to merge 4 commits into
RocketChat:developfrom
Jbansal2:fix/iemoji-type-standardization
Open

fix: standardize IEmoji types and remove unsafe emoji casts#41275
Jbansal2 wants to merge 4 commits into
RocketChat:developfrom
Jbansal2:fix/iemoji-type-standardization

Conversation

@Jbansal2

@Jbansal2 Jbansal2 commented Jul 9, 2026

Copy link
Copy Markdown

Summary

This PR improves type safety in the emoji system by replacing the permissive IEmoji type with well-defined interfaces and removing unsafe type assertions used by the custom emoji implementation.

Changes

  • Replace the permissive IEmoji ([x: string]: any) with a typed union:
    • INativeEmoji
    • IEmojiAlias
    • ICustomEmojiListEntry
  • Standardize EmojiPackages.list to use the new IEmoji type.
  • Remove unsafe as unknown as and as any casts from the custom emoji implementation.
  • Create explicit typed objects for custom emoji and alias entries.
  • Add type guards for safe access to aliasOf and extension.
  • Update emoji event payload types in Events.ts and streams.ts to use IEmojiCustom, matching the runtime payload.

Why

The previous implementation relied on an overly permissive IEmoji type and unsafe type assertions because the emoji list and event payloads were not consistently typed.

This change standardizes emoji pack types, improves type safety, and removes the need for unsafe casts while preserving the existing runtime behavior.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved custom emoji update/delete flows, including rename behavior and automatic alias cleanup.
    • Custom emoji rendering is more defensive when resolving targets, reducing broken or incorrect HTML output.
    • Emoji data and alias handling are now more consistent across the app, improving reliability for package-based and alias entries.

- replace the permissive IEmoji type with typed emoji interfaces
- standardize emoji pack entry types
- remove unsafe type assertions from custom emoji handling
- update emoji event payloads to use IEmojiCustom
- add type guards for safe property access

Resolves RocketChat#41265
@Jbansal2
Jbansal2 requested review from a team as code owners July 9, 2026 09:18
@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7ebad4d

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

@dionisio-bot

dionisio-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

@CLAassistant

CLAassistant commented Jul 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d1e62b6-c31e-4aca-ab89-2ed3b5f2ec79

📥 Commits

Reviewing files that changed from the base of the PR and between 2aa4082 and d3ee914.

📒 Files selected for processing (1)
  • apps/meteor/client/lib/customEmoji.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/lib/customEmoji.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: CodeRabbit / Review
⚠️ CI failures not shown inline (1)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ❌ **Has milestone or project** — This PR is missing the required milestone or project
- ✅ **Valid PR title**
- ✅ **Correct target version**

Walkthrough

This PR replaces the permissive IEmoji interface with structured emoji entry types and updates emoji registry, custom emoji mutation/rendering, and event payload typings to use the refined models.

Changes

Emoji type refactor

Layer / File(s) Summary
IEmoji type definitions
packages/core-typings/src/IEmoji.ts
Defines structured native, alias, and custom emoji entry interfaces and combines them into the IEmoji union.
Emoji package registry typing
apps/meteor/app/emoji/lib/rocketchat.ts
Types EmojiPackages.list as Record<string, IEmoji>.
Custom emoji update/delete/render logic
apps/meteor/client/lib/customEmoji.ts
Adds CustomEmojiUpdate, types custom emoji mutations, rebuilds aliases during renames, and guards rendering against missing alias or extension data.
Custom emoji registration hook
apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
Creates explicitly typed custom emoji and alias registry entries.
Event and stream signature typing
packages/core-services/src/events/Events.ts, packages/ddp-client/src/types/streams.ts
Uses IEmojiCustom for custom emoji update and deletion event payloads.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels: type: chore

Suggested reviewers: MartinSchoeler, ricardogarim, gabriellsh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: tightening and standardizing emoji typing while removing unsafe casts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/core-typings/src/IEmoji.ts (1)

3-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Narrow emojiPackage to the known literal values. It only appears as 'native' and 'emojiCustom', so using those literals in the subtypes would make IEmoji a discriminated union and improve narrowing.

🤖 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 `@packages/core-typings/src/IEmoji.ts` around lines 3 - 5, Narrow the shared
emoji discriminator so `IEmojiBase.emojiPackage` uses the known literal values
instead of a broad string, and update the concrete emoji subtypes in `IEmoji` to
set that field to `'native'` and `'emojiCustom'`. This will make `IEmoji` work
as a discriminated union and allow TypeScript to narrow correctly based on
`emojiPackage`.
🤖 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/lib/customEmoji.ts`:
- Around line 138-149: Guard the custom emoji lookup in customRender against
undefined dataCheck before using the in operator. In the alias resolution branch
and the extension check branch, add an explicit truthy check for dataCheck
before testing aliasOf or extension, since emoji.list[shortname] or the alias
target can be missing. Keep the existing shortname fallback behavior when
dataCheck is absent, and make sure the span rendering path only runs when
dataCheck is a valid object.

---

Nitpick comments:
In `@packages/core-typings/src/IEmoji.ts`:
- Around line 3-5: Narrow the shared emoji discriminator so
`IEmojiBase.emojiPackage` uses the known literal values instead of a broad
string, and update the concrete emoji subtypes in `IEmoji` to set that field to
`'native'` and `'emojiCustom'`. This will make `IEmoji` work as a discriminated
union and allow TypeScript to narrow correctly based on `emojiPackage`.
🪄 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: 85a1cdb0-bd07-494e-996c-f3ac852bffe2

📥 Commits

Reviewing files that changed from the base of the PR and between f633d7e and 2aa4082.

📒 Files selected for processing (6)
  • apps/meteor/app/emoji/lib/rocketchat.ts
  • apps/meteor/client/lib/customEmoji.ts
  • apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
  • packages/core-services/src/events/Events.ts
  • packages/core-typings/src/IEmoji.ts
  • packages/ddp-client/src/types/streams.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (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/app/emoji/lib/rocketchat.ts
  • packages/core-services/src/events/Events.ts
  • packages/core-typings/src/IEmoji.ts
  • apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
  • packages/ddp-client/src/types/streams.ts
  • apps/meteor/client/lib/customEmoji.ts
🧠 Learnings (5)
📚 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/app/emoji/lib/rocketchat.ts
  • packages/core-services/src/events/Events.ts
  • packages/core-typings/src/IEmoji.ts
  • apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
  • packages/ddp-client/src/types/streams.ts
  • apps/meteor/client/lib/customEmoji.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/app/emoji/lib/rocketchat.ts
  • packages/core-services/src/events/Events.ts
  • packages/core-typings/src/IEmoji.ts
  • apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
  • packages/ddp-client/src/types/streams.ts
  • apps/meteor/client/lib/customEmoji.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/app/emoji/lib/rocketchat.ts
  • packages/core-services/src/events/Events.ts
  • packages/core-typings/src/IEmoji.ts
  • apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
  • packages/ddp-client/src/types/streams.ts
  • apps/meteor/client/lib/customEmoji.ts
📚 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/root/hooks/loggedIn/useCustomEmoji.ts
  • apps/meteor/client/lib/customEmoji.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/root/hooks/loggedIn/useCustomEmoji.ts
  • apps/meteor/client/lib/customEmoji.ts
🔇 Additional comments (6)
packages/core-typings/src/IEmoji.ts (1)

10-42: LGTM!

The type definitions are well-structured with accurate required and optional fields. The downstream consumers in customEmoji.ts and useCustomEmoji.ts construct objects matching these shapes, and the native emoji registration in emoji-native/server/lib.ts produces INativeEmoji-compatible entries.

apps/meteor/app/emoji/lib/rocketchat.ts (1)

1-1: LGTM!

The import type for IEmoji and the Record<string, IEmoji> typing on EmojiPackages.list are clean and correct. Downstream consumers write INativeEmoji, ICustomEmojiListEntry, and IEmojiAlias objects to emoji.list, all compatible with the union type.

Also applies to: 17-25

packages/core-services/src/events/Events.ts (1)

5-5: LGTM!

Also applies to: 68-69

packages/ddp-client/src/types/streams.ts (1)

9-9: LGTM!

Also applies to: 206-207

apps/meteor/client/lib/customEmoji.ts (1)

1-13: LGTM!

Also applies to: 24-41, 58-87

apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts (1)

1-1: LGTM!

Also applies to: 42-56

Comment thread apps/meteor/client/lib/customEmoji.ts

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/ddp-client/src/types/streams.ts Outdated
Comment thread apps/meteor/client/lib/customEmoji.ts
Comment thread apps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.ts
Comment thread packages/core-services/src/events/Events.ts Outdated
- add undefined guards for dataCheck in customRender
- update stream type to include previousName for emoji updates
- update event signature to include previousName and previousExtension

@Jbansal2 Jbansal2 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

.

Commented in CodeRabbit Change Stack

@Jbansal2

Copy link
Copy Markdown
Author

Hi maintainers! The implementation is ready for review. The remaining Dionisio QA check appears to be failing because the PR is missing the required QA label and milestone/project. Since I'm a community contributor, I don't have permission to add these. Could someone please assign the appropriate metadata? Thank you!

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.

2 participants