Skip to content

refactor(ui-client): improve Callbacks class typing v2#38627

Open
TheRazorbill wants to merge 4 commits into
RocketChat:developfrom
TheRazorbill:improve/ui-client-callbacks-typing
Open

refactor(ui-client): improve Callbacks class typing v2#38627
TheRazorbill wants to merge 4 commits into
RocketChat:developfrom
TheRazorbill:improve/ui-client-callbacks-typing

Conversation

@TheRazorbill
Copy link
Copy Markdown
Contributor

@TheRazorbill TheRazorbill commented Feb 11, 2026

Proposed changes

This PR improves TypeScript type safety in the Callbacks utility by:

  • Replacing loose generic constraints ([key: string]: (item: any, constant?: any) => any)
    with stricter Record<string, ...Signature> types
  • Introducing semantic callback signature types:
    • EventLikeCallbackSignature (side-effect callbacks)
    • ChainedCallbackSignature (value-transforming callbacks)
  • Reducing unnecessary any casts in the static create method
  • Improving inline documentation with clearer JSDoc comments
  • Updating the callback constant parameter to be optional for better flexibility

These changes improve maintainability and typing accuracy while preserving backward compatibility and runtime behavior.


Proposed changes (including screenshots)

Before / After

image image

Issue(s)

Closes: #38827

Steps to test or reproduce

  • Run TypeScript checks locally
  • Ensure the project builds successfully with no type errors

Example:

yarn lint
yarn test


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

* **Refactor**
  * Strengthened callback and event typings with clearer semantic signatures and stricter generic constraints for safer development and better IDE autocomplete.
  * Made the callback "constant" parameter optional for more flexible usage.
  * Introduced a reusable action-listener type and a typed avatar-path function; narrowed the hook return type to that signature.
  * No user-facing behavior changed; backward compatible.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Copilot AI review requested due to automatic review settings February 11, 2026 21:49
@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: 89fc991

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-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/meteor Patch
@rocket.chat/gazzodown Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-video-conf 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/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/models 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

Tightens TypeScript typings across UI packages: refactors Callbacks signatures and generics, introduces a typed ActionEventListener for action manager listeners, and adds a structured GetRoomPathAvatar type (propagated to the useRoomAvatarPath hook); also adds a changeset entry documenting the callbacks typing change.

Changes

Cohort / File(s) Summary
Changeset Entry
\.changeset/improve-callbacks-typing.md
Adds a changeset documenting the Callbacks typing refactor.
Callbacks Type Refactoring
packages/ui-client/src/lib/callbacks/Callbacks.ts
Adds EventLikeCallbackSignature and ChainedCallbackSignature; switches generics to Record<string, ...>; updates Callbacks class signature, static create overloads/return typing, internal initialization, and makes callback constant parameter optional in public interfaces.
Action Manager Listener Types
packages/ui-contexts/src/ActionManagerContext.ts
Adds ActionEventListener<T> type and replaces inline (data: any) listener types with ActionEventListener<UiKit.ServerInteraction> for on/off overloads.
Avatar URL Getter Typing
packages/ui-contexts/src/AvatarUrlContext.ts
Adds GetRoomPathAvatar type (object-parameter) and replaces getRoomPathAvatar: (...args: any) => string with GetRoomPathAvatar.
Hook Return Type Narrowing
packages/ui-contexts/src/hooks/useRoomAvatarPath.ts
Imports GetRoomPathAvatar and narrows useRoomAvatarPath return type to GetRoomPathAvatar (no runtime behavior changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I hopped through lines of code so snappy,
Swapped loose any for types that’re happy,
Listeners and avatars now neatly named,
Callbacks tightened — nothing renamed,
A rabbit cheers — typings all tidy! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(ui-client): improve Callbacks class typing v2' accurately summarizes the main change—a refactor to improve TypeScript typing in the Callbacks class by introducing semantic callback signature types and stricter generic constraints.
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.

📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

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 packages/ui-client’s legacy Callbacks utility to improve TypeScript typing by introducing semantic callback signature aliases and tightening generic constraints.

Changes:

  • Introduces EventLikeCallbackSignature / ChainedCallbackSignature helper types and uses them in Callbacks generic constraints.
  • Refactors Callbacks.create factory typing and reduces any casting.
  • Makes the “constant” callback parameter optional in the deprecated Cb helper type and adds a changeset.

Reviewed changes

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

File Description
packages/ui-client/src/lib/callbacks/Callbacks.ts Adds new signature types, changes generic constraints, and refactors Callbacks.create/Cb typing.
.changeset/improve-callbacks-typing.md Declares a patch release note for the typing refactor.

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

Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts Outdated
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts Outdated
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts
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: 2

🤖 Fix all issues with AI agents
In `@packages/ui-client/src/lib/callbacks/Callbacks.ts`:
- Around line 236-241: Remove the redundant no-op cast by deleting the typedHook
variable and use the existing hook parameter directly; update the return object
so add/remove/run call callbacks.add(hook,...), callbacks.remove(hook,...), and
callbacks.run(hook,...) instead of referencing typedHook, ensuring you only
change the alias usage and not the callbacks methods themselves.
- Around line 16-26: Change EventLikeCallbackSignature to return void (not "void
| unknown") so it is distinct from ChainedCallbackSignature; update the type
definition named EventLikeCallbackSignature in Callbacks.ts to enforce void and
keep ChainedCallbackSignature as returning unknown, and update any related uses
(e.g., event callbacks like afterCreateChannel, afterSaveMessage, usernameSet in
clientCallbacks.ts) if necessary to satisfy the stricter void return. Also
remove the redundant cast "const typedHook = hook as string" and use the
existing hook parameter directly (the parameter named hook is already a string),
eliminating the unused/duplicative typedHook variable.
🧹 Nitpick comments (1)
packages/ui-client/src/lib/callbacks/Callbacks.ts (1)

16-19: JSDoc comments added on type declarations.

The coding guideline for **/*.{ts,tsx,js} states: "Avoid code comments in the implementation." The file already has JSDoc comments on methods (lines 125–132, 205–212, etc.), so this is consistent with the existing pattern, but these new comments are additions in this PR.

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

Also applies to: 22-25

📜 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 4ab8b3f.

📒 Files selected for processing (2)
  • .changeset/improve-callbacks-typing.md
  • packages/ui-client/src/lib/callbacks/Callbacks.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-client/src/lib/callbacks/Callbacks.ts
🧬 Code graph analysis (1)
packages/ui-client/src/lib/callbacks/Callbacks.ts (2)
apps/meteor/server/lib/callbacks.ts (1)
  • callbacks (218-226)
packages/livechat/src/widget.ts (1)
  • callback (509-511)
⏰ 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: cubic · AI code reviewer
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: Agent
🔇 Additional comments (3)
packages/ui-client/src/lib/callbacks/Callbacks.ts (2)

40-43: LGTM!

The updated generic constraints using Record<string, ChainedCallbackSignature> and Record<string, EventLikeCallbackSignature> are cleaner than the previous index-signature approach and compatible with the existing usage in apps/meteor/server/lib/callbacks.ts.


250-257: LGTM!

Making constant optional in the Cb type is consistent with how it's treated throughout the class (e.g., line 29, line 149, line 203) and aligns with the runtime behavior where the constant is frequently omitted.

.changeset/improve-callbacks-typing.md (1)

1-5: LGTM!

Changeset correctly identifies this as a patch — appropriate for a non-breaking typing improvement.

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

Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts Outdated
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.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

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-client/src/lib/callbacks/Callbacks.ts">

<violation number="1" location="packages/ui-client/src/lib/callbacks/Callbacks.ts:20">
P2: The return type `void | unknown` simplifies to `unknown` in TypeScript (since `unknown` is the top type), making `EventLikeCallbackSignature` structurally identical to `ChainedCallbackSignature`. This defeats the semantic distinction between side-effect callbacks and value-transforming callbacks. Consider using just `void` to enforce the intended behavior for event-like callbacks.</violation>
</file>

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

Comment thread packages/ui-client/src/lib/callbacks/Callbacks.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 4 out of 4 changed files in this pull request and generated 5 comments.


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

Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts Outdated
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts
Comment thread .changeset/improve-callbacks-typing.md Outdated
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.ts
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 .changeset/improve-callbacks-typing.md
Comment thread packages/ui-client/src/lib/callbacks/Callbacks.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 1 comment.


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

Comment thread packages/ui-contexts/src/AvatarUrlContext.ts
@TheRazorbill
Copy link
Copy Markdown
Contributor Author

I've opened this second PR to refine the Callbacks utility typing in @rocket.chat/ui-client. My goal was to replace the loose any constraints with stricter semantic signatures (EventLike and Chained) to prevent future typing regressions.

I have already:

Addressed the feedback from the AI reviewers regarding return types (void vs unknown).
Included a changeset as this affects multiple packages.
Ensured backward compatibility with existing callback implementations.
I'd appreciate your thoughts on this approach. Does this align with how we want to handle utility typings moving forward?
Whenever you have time to check it, please let me know if any further changes are needed for the approval.

Thanks!

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 7 out of 7 changed files in this pull request and generated no new comments.


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

- Add semantic callback signature types (EventLikeCallbackSignature returns void,
  ChainedCallbackSignature returns any) enforcing structural distinction
- Replace loose index-signature generic constraints with Record<string, ...>
- Add Awaited<> wrapper on run() return types for correct async/sync handling
- Restore function-type generic overload on Callbacks.create for backward compat
- Remove redundant 'as any' casts in static create method, use typed callbacks
- Make Cb.add constant parameter optional for flexibility
- Add ActionEventListener<T> type replacing inline (data: any) listeners
- Add structured GetRoomPathAvatar type matching actual implementation
- Narrow useRoomAvatarPath return type to GetRoomPathAvatar
- Add changeset for both ui-client and ui-contexts packages
@TheRazorbill TheRazorbill force-pushed the improve/ui-client-callbacks-typing branch from b4d3417 to 0fd796f Compare February 22, 2026 01:13
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.65%. Comparing base (afaabea) to head (9cb8344).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38627      +/-   ##
===========================================
- Coverage    70.67%   70.65%   -0.02%     
===========================================
  Files         3191     3191              
  Lines       112963   112965       +2     
  Branches     20451    20488      +37     
===========================================
- Hits         79832    79814      -18     
- Misses       31085    31098      +13     
- Partials      2046     2053       +7     
Flag Coverage Δ
e2e 60.35% <ø> (-0.03%) ⬇️
e2e-api 47.77% <ø> (ø)
unit 71.27% <75.00%> (-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-client: Refactor Callbacks utility for better type safety

2 participants