Skip to content

refactor(ui-contexts): improve ActionManager and AvatarUrl typing#38626

Open
TheRazorbill wants to merge 15 commits into
RocketChat:developfrom
TheRazorbill:improve/ui-contexts-typing
Open

refactor(ui-contexts): improve ActionManager and AvatarUrl typing#38626
TheRazorbill wants to merge 15 commits into
RocketChat:developfrom
TheRazorbill:improve/ui-contexts-typing

Conversation

@TheRazorbill
Copy link
Copy Markdown
Contributor

@TheRazorbill TheRazorbill commented Feb 11, 2026

Proposed changes (including screenshots)

This PR improves TypeScript type safety in ui-contexts by refining the typings of the ActionManager and Avatar URL contexts.

Changes included:

  • Replace generic any listener types in IActionManager with a semantic ActionEventListener
  • Preserve the ergonomic destructuring overload for the "busy" event listener
  • Introduce a GetRoomPathAvatar type with explicit overloads for getRoomPathAvatar
  • Improve inline documentation for better clarity and IDE autocomplete

These updates are purely type-level improvements with no runtime or behavioral impact, maintaining backward compatibility with existing implementations.

Before / After

image image ---

Issue(s)

Closes: #38826

Steps to test or reproduce

Run TypeScript checks locally and ensure the project builds successfully with no type errors:

yarn lint
yarn test


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Refactor**
  * Strengthened typing for action event listeners and standardized subscribe/unsubscribe signatures for safer, consistent event handling without behavioral changes.
  * Reworked avatar URL retrieval API to support clearer overload-style parameters (id/etag or structured params), updated related hook return typing, and exported the new avatar-path type for clearer usage.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

- Replace generic `any` types with typed ActionEventListener in IActionManager
- Create GetRoomPathAvatar type with explicit function overloads for getRoomPathAvatar
- Maintain destructuring pattern for 'busy' event listener ergonomics
- Add JSDoc documentation for clarity
- All tests pass without breaking changes

Improvements:
- Remove unnecessary `any` type casts
- Add semantic type definitions for event listeners
- Improve IDE autocomplete and type inference
- Maintain backward compatibility with existing implementations
@TheRazorbill TheRazorbill requested a review from a team as a code owner February 11, 2026 21:42
Copilot AI review requested due to automatic review settings February 11, 2026 21:42
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 11, 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 Feb 11, 2026

🦋 Changeset detected

Latest commit: 728da5c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/ui-contexts Patch
@rocket.chat/meteor Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/models Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 11, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Type-only refinements across packages/ui-contexts: ActionManagerContext introduces ActionEventListener<T> and narrows IActionManager.on/off to ActionEventListener<UiKit.ServerInteraction>; AvatarUrlContext adds an overloaded GetRoomPathAvatar type and updates getRoomPathAvatar; related hook and public export types updated accordingly.

Changes

Cohort / File(s) Summary
Action Manager Types
packages/ui-contexts/src/ActionManagerContext.ts
Added type ActionEventListener<T = unknown> = (data: T) => void; and changed IActionManager.on(viewId, listener) and IActionManager.off(viewId, listener) to use ActionEventListener<UiKit.ServerInteraction> instead of untyped (data: any) => ....
Avatar URL Types
packages/ui-contexts/src/AvatarUrlContext.ts
Added overloaded type GetRoomPathAvatar with signatures (roomId: string, etag?: string) => string and (params: { roomId?: string; roomName?: string; etag?: string; type?: string }) => string; replaced getRoomPathAvatar: (...args: any) => string with getRoomPathAvatar: GetRoomPathAvatar.
Hook return typing
packages/ui-contexts/src/hooks/useRoomAvatarPath.ts
Imported AvatarUrlContextValue and refined useRoomAvatarPath return type to AvatarUrlContextValue['getRoomPathAvatar'] (type-only change).
Public exports
packages/ui-contexts/src/index.ts
Adjusted exports to include GetRoomPathAvatar from AvatarUrlContext (reordered into separate export lines).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibble types with whiskers keen,
Tuned listeners and avatars clean.
Signatures hopped into a neat row,
Small hops of code all set to go.
A joyful twitch — the interfaces glow.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: improving TypeScript typing for ActionManager and AvatarUrl contexts in the ui-contexts package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors @rocket.chat/ui-contexts type definitions to improve TypeScript safety for the ActionManager event listeners and the room-avatar URL getter.

Changes:

  • Introduces ActionEventListener to replace any listener typings in IActionManager while keeping the "busy" overload.
  • Replaces getRoomPathAvatar: (...args: any) => string with a new overloaded GetRoomPathAvatar type.
  • Adds/updates inline JSDoc comments intended to improve IDE autocomplete/documentation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/ui-contexts/src/AvatarUrlContext.ts Adds a new overloaded GetRoomPathAvatar type and applies it to AvatarUrlContextValue.
packages/ui-contexts/src/ActionManagerContext.ts Replaces any listener types with a new ActionEventListener type for on/off.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts
Comment thread packages/ui-contexts/src/ActionManagerContext.ts Outdated
Comment thread packages/ui-contexts/src/AvatarUrlContext.ts Outdated
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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/ui-contexts/src/ActionManagerContext.ts`:
- Line 8: The ActionEventListener type currently returns unknown and doesn't
match the ActionManager implementation signatures; change the type to
ActionEventListener = (data: unknown) => void (or (data: any) => void if you
prefer) and update the ActionManager methods on() and off() to accept listeners
typed as ActionEventListener (or (data: unknown) => void) so the interface and
implementation signatures align (also ensure any overloads such as the 'busy'
event use the same void return type).
🧹 Nitpick comments (3)
packages/ui-contexts/src/AvatarUrlContext.ts (2)

5-7: Remove the JSDoc comment per coding guidelines.

As per coding guidelines, **/*.{ts,tsx,js}: "Avoid code comments in the implementation".

Proposed fix
-/**
- * Type for room avatar path getter function with multiple overloads
- */
 type GetRoomPathAvatar = {

8-20: Consider aligning the style with getUserPathAvatar.

getUserPathAvatar (lines 15–18) defines its overloads inline, while getRoomPathAvatar uses an extracted type. For consistency, either inline GetRoomPathAvatar or extract getUserPathAvatar into a named type as well.

packages/ui-contexts/src/ActionManagerContext.ts (1)

5-7: Remove the JSDoc comment per coding guidelines.

As per coding guidelines, **/*.{ts,tsx,js}: "Avoid code comments in the implementation".

Proposed fix
-/**
- * Type for generic action manager event listener
- */
 type ActionEventListener = (data: unknown) => unknown;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d9eb6a and f334b59.

📒 Files selected for processing (2)
  • packages/ui-contexts/src/ActionManagerContext.ts
  • packages/ui-contexts/src/AvatarUrlContext.ts
🧰 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:

  • packages/ui-contexts/src/ActionManagerContext.ts
  • packages/ui-contexts/src/AvatarUrlContext.ts
⏰ 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). (3)
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: Agent
  • GitHub Check: cubic · AI code reviewer

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread packages/ui-contexts/src/ActionManagerContext.ts Outdated
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 2 files

TheRazorbill and others added 2 commits February 11, 2026 18:50
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Replace generic `any` types with typed ActionEventListener<T> generic
- Make ActionEventListener return void (idiomatic for event handlers)
- Type listener parameter with UiKit.ServerInteraction for improved type safety
- Export GetRoomPathAvatar type for reuse across package
- Add function overload support to GetRoomPathAvatar for flexibility
- Maintain destructuring pattern for 'busy' event listener ergonomics
- All tests pass without breaking changes

Improvements:
- Better type inference at callsites via generic parameter
- Generic type parameter supports future extensions
- Exported types prevent any leakage in dependent code
- Improved JSDoc documentation for clarity
- Supports multiple ways to call getRoomPathAvatar
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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/ui-contexts/src/AvatarUrlContext.ts`:
- Line 9: GetRoomPathAvatar's params are all optional and mismatch actual
callers (RoomAvatar.tsx) while useRoomAvatarPath returns loose any, so tighten
the API: change the GetRoomPathAvatar type to require either roomId or roomName
(e.g., a discriminated union like ({ roomId: string } | { roomName: string }) &
{ etag?: string; type?: string }), or provide overloads that mirror
getUserPathAvatar to support both positional and object styles; rename or map
param keys to match caller fields (_id, t, avatarETag) or adapt callers to the
declared keys; and update useRoomAvatarPath's return signature from (...args:
any) => string to the new GetRoomPathAvatar type so callers are properly
type-checked (references: GetRoomPathAvatar, useRoomAvatarPath, RoomAvatar.tsx,
getUserPathAvatar).
🧹 Nitpick comments (1)
packages/ui-contexts/src/AvatarUrlContext.ts (1)

5-8: Remove the JSDoc comment per coding guidelines.

As per coding guidelines, **/*.{ts,tsx,js} files should "Avoid code comments in the implementation."

Proposed fix
-/**
- * Type for room avatar path getter function.
- * The provider implementation expects a single parameter object.
- */
 type GetRoomPathAvatar = (params: { roomId?: string; roomName?: string; etag?: string; type?: string }) => string;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f334b59 and 60ee28f.

📒 Files selected for processing (1)
  • packages/ui-contexts/src/AvatarUrlContext.ts
🧰 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:

  • packages/ui-contexts/src/AvatarUrlContext.ts
🧠 Learnings (2)
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • packages/ui-contexts/src/AvatarUrlContext.ts
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • packages/ui-contexts/src/AvatarUrlContext.ts
⏰ 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 comments (1)
packages/ui-contexts/src/AvatarUrlContext.ts (1)

17-17: Type integration looks good.

Replacing the permissive (...args: any) => string with a named type improves discoverability and type safety — contingent on the type definition concerns raised above being addressed.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts Outdated
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.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/ui-contexts/src/ActionManagerContext.ts">

<violation number="1" location="packages/ui-contexts/src/ActionManagerContext.ts:16">
P2: Overload order causes on('busy', ...) to match the generic string signature first, breaking contextual typing for the busy event listener.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread packages/ui-contexts/src/ActionManagerContext.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts
…tarPath typing

- Update useRoomAvatarPath to return AvatarUrlContextValue['getRoomPathAvatar'] instead of (...args: any) => string
- Export GetRoomPathAvatar type for external consumers
- Aligns with useUserAvatarPath pattern for consistency
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts Outdated
…lementation

- Change from overloaded signatures to single function signature accepting room object
- Matches actual AvatarUrlProvider implementation which expects { _id, type?, t?, avatarETag?, ... }
- Addresses Copilot feedback about type mismatch with provider implementation
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.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/ui-contexts/src/AvatarUrlContext.ts">

<violation number="1" location="packages/ui-contexts/src/AvatarUrlContext.ts:9">
P2: Exported GetRoomPathAvatar type was narrowed to only accept a room object, removing previously supported overloads (roomId string or params). This is a breaking API change for consumers still using the old signatures.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts Outdated
Comment thread packages/ui-contexts/src/ActionManagerContext.ts Outdated
TheRazorbill and others added 2 commits February 11, 2026 20:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TheRazorbill TheRazorbill force-pushed the improve/ui-contexts-typing branch from 1f3246f to 19c3f86 Compare February 19, 2026 23:53
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.68%. Comparing base (afaabea) to head (1ea484f).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38626      +/-   ##
===========================================
+ Coverage    70.67%   70.68%   +0.01%     
===========================================
  Files         3191     3191              
  Lines       112963   112963              
  Branches     20451    20480      +29     
===========================================
+ Hits         79832    79853      +21     
+ Misses       31085    31064      -21     
  Partials      2046     2046              
Flag Coverage Δ
unit 71.32% <76.92%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

ui-contexts: Improve type safety for ActionManager and AvatarUrl Contexts

2 participants