fix: standardize IEmoji types and remove unsafe emoji casts - #41275
fix: standardize IEmoji types and remove unsafe emoji casts#41275Jbansal2 wants to merge 4 commits into
Conversation
- 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
|
|
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 |
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
|
| 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
- Fix the IEmoji type and standardize the emoji packs types #41265: Covers the related standardization of
IEmojiand emoji-pack typings in the custom emoji code.
Possibly related PRs
- RocketChat/Rocket.Chat#39411: Touches the shared emoji type and rendering surfaces updated by this PR.
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.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/core-typings/src/IEmoji.ts (1)
3-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNarrow
emojiPackageto the known literal values. It only appears as'native'and'emojiCustom', so using those literals in the subtypes would makeIEmojia 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
📒 Files selected for processing (6)
apps/meteor/app/emoji/lib/rocketchat.tsapps/meteor/client/lib/customEmoji.tsapps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.tspackages/core-services/src/events/Events.tspackages/core-typings/src/IEmoji.tspackages/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.tspackages/core-services/src/events/Events.tspackages/core-typings/src/IEmoji.tsapps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.tspackages/ddp-client/src/types/streams.tsapps/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.tspackages/core-services/src/events/Events.tspackages/core-typings/src/IEmoji.tsapps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.tspackages/ddp-client/src/types/streams.tsapps/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.tspackages/core-services/src/events/Events.tspackages/core-typings/src/IEmoji.tsapps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.tspackages/ddp-client/src/types/streams.tsapps/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.tspackages/core-services/src/events/Events.tspackages/core-typings/src/IEmoji.tsapps/meteor/client/views/root/hooks/loggedIn/useCustomEmoji.tspackages/ddp-client/src/types/streams.tsapps/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.tsapps/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.tsapps/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.tsanduseCustomEmoji.tsconstruct objects matching these shapes, and the native emoji registration inemoji-native/server/lib.tsproducesINativeEmoji-compatible entries.apps/meteor/app/emoji/lib/rocketchat.ts (1)
1-1: LGTM!The
import typeforIEmojiand theRecord<string, IEmoji>typing onEmojiPackages.listare clean and correct. Downstream consumers writeINativeEmoji,ICustomEmojiListEntry, andIEmojiAliasobjects toemoji.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
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
- 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
left a comment
There was a problem hiding this comment.
.
Commented in CodeRabbit Change Stack
|
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! |
Summary
This PR improves type safety in the emoji system by replacing the permissive
IEmojitype with well-defined interfaces and removing unsafe type assertions used by the custom emoji implementation.Changes
IEmoji([x: string]: any) with a typed union:INativeEmojiIEmojiAliasICustomEmojiListEntryEmojiPackages.listto use the newIEmojitype.as unknown asandas anycasts from the custom emoji implementation.aliasOfandextension.Events.tsandstreams.tsto useIEmojiCustom, matching the runtime payload.Why
The previous implementation relied on an overly permissive
IEmojitype 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.
Summary by CodeRabbit