Skip to content

chore: improve GenericMenu TypeScript typing#38594

Open
TheRazorbill wants to merge 9 commits into
RocketChat:developfrom
TheRazorbill:fix/improve-generic-menu-typing
Open

chore: improve GenericMenu TypeScript typing#38594
TheRazorbill wants to merge 9 commits into
RocketChat:developfrom
TheRazorbill:fix/improve-generic-menu-typing

Conversation

@TheRazorbill
Copy link
Copy Markdown
Contributor

@TheRazorbill TheRazorbill commented Feb 10, 2026

Proposed changes

This PR improves TypeScript type safety in GenericMenu by:

  • Adding an explicit ReactElement type for the button prop
  • Removing an unnecessary as any cast in cloneElement

This ensures button is safely clonable and avoids unsafe type assertions, without changing runtime behavior.

Issue(s)

Closes #38748

Steps to test or reproduce

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

Example:

yarn lint
yarn test

Before
image

After
image image

Summary by CodeRabbit

  • New Features

    • Added a customizable button element for the menu component to allow flexible button content and appearance.
  • Refactor

    • Improved menu component robustness and type safety for more reliable behavior.
  • Chores

    • Expanded image-size tracking to run in more scenarios and adjusted default platform behavior.
    • Strengthened API error response validation for the custom sounds endpoint.

Copilot AI review requested due to automatic review settings February 10, 2026 18:21
@dionisio-bot
Copy link
Copy Markdown
Contributor

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

🦋 Changeset detected

Latest commit: b553092

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

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37f4453 and 3016926.

📒 Files selected for processing (5)
  • .changeset/chatty-hounds-reflect.md
  • .github/actions/docker-image-size-tracker/action.yml
  • .github/workflows/ci.yml
  • apps/meteor/app/api/server/v1/custom-sounds.ts
  • packages/ui-client/src/components/GenericMenu/GenericMenu.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ui-client/src/components/GenericMenu/GenericMenu.tsx
  • .changeset/chatty-hounds-reflect.md
🧰 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/api/server/v1/custom-sounds.ts
🔇 Additional comments (3)
.github/actions/docker-image-size-tracker/action.yml (1)

29-29: LGTM — sensible default.

Switching the default platform from arm64 to amd64 aligns with the more common CI architecture.

.github/workflows/ci.yml (1)

453-453: LGTM — condition now correctly enables tracking on develop pushes.

The added github.ref == 'refs/heads/develop' clause ensures the step actually runs when the job is triggered by a develop push, not just for same-repo PRs. This aligns with the job-level if on line 443.

apps/meteor/app/api/server/v1/custom-sounds.ts (1)

4-9: LGTM — standardized error response validation added.

The error response validators for 400, 401, and 403 are cleanly imported and wired into the endpoint definition, following the established pattern for response schema validation.

Also applies to: 55-57


Walkthrough

GenericMenu gained a typed button prop (ReactElement) and removed an unsafe as any cast from an early-return cloneElement. A patch changeset was added. Separately, CI workflow inputs/conditions were adjusted and a server endpoint's response schemas were extended with additional error validations.

Changes

Cohort / File(s) Summary
GenericMenu Type Safety
packages/ui-client/src/components/GenericMenu/GenericMenu.tsx
Imported ReactElement, added button: ReactElement to GenericMenuCommonProps, and removed the as any cast from cloneElement to make cloning type-safe.
Changeset
.changeset/chatty-hounds-reflect.md
Added a patch changeset for @rocket.chat/ui-client documenting the type-safety improvement.
CI Actions / Workflow
.github/actions/docker-image-size-tracker/action.yml, .github/workflows/ci.yml
Default platform input changed from arm64 to amd64; CI step condition expanded to also run on develop refs in addition to PRs from the same repo.
API Response Validation
apps/meteor/app/api/server/v1/custom-sounds.ts
Imported additional error validators and extended the custom-sounds.list endpoint schema to include 400, 401, and 403 error response validations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through props and chased the cast away,
Typed buttons now bounce in a safer array.
CI hums a new tune, errors get their say,
I nibble bugs gently and then hop away. 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated changes: default platform value change in docker-image-size-tracker action, CI workflow conditional change, and error validations in custom-sounds API endpoint. Remove out-of-scope changes unrelated to GenericMenu typing improvements (.github files and custom-sounds.ts), or address them in separate PRs with their own objectives.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: improving TypeScript typing for the GenericMenu component by adding ReactElement type and removing the 'as any' cast.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #38748: added ReactElement type to button prop and removed 'as any' assertion, improving type safety without changing runtime behavior.
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 1 file

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

Improves the TypeScript typing of GenericMenu’s button prop to ensure it is clonable and removes an unsafe as any cast, aiming to increase type safety without changing runtime behavior.

Changes:

  • Adds an explicit ReactElement type for the button prop.
  • Removes the as any cast when calling cloneElement(button, ...).

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

@TheRazorbill
Copy link
Copy Markdown
Contributor Author

Thanks for the reviews! This is a small type-safety improvement only, with no runtime behavior changes. Happy to adjust anything if needed.

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)
.changeset/chatty-hounds-reflect.md (1)

1-5: LGTM! Changeset is well-formed and appropriate.

The changeset correctly uses patch for a type-safety improvement with no runtime behavior changes, and the format follows changesets conventions.

Optional suggestion: Consider making the description slightly more specific to help future readers understand what changed:

📝 More detailed description option
 ---
 '@rocket.chat/ui-client': patch
 ---
 
-Improve type safety for GenericMenu component props
+Improve type safety for GenericMenu component by adding ReactElement type to button prop and removing 'as any' cast
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.changeset/chatty-hounds-reflect.md around lines 1 - 5, Update the changeset
description to be more specific about what changed: clarify that the patch
improves type safety for the GenericMenu component's props (e.g., tighten prop
generics or typings), mention that this is a non-runtime change, and keep the
changeset type as 'patch' for package '@rocket.chat/ui-client' so readers
immediately know which component and package the change affects.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ec201c and 37f4453.

📒 Files selected for processing (1)
  • .changeset/chatty-hounds-reflect.md
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.changeset/chatty-hounds-reflect.md:
- Around line 1-5: Update the changeset description to be more specific about
what changed: clarify that the patch improves type safety for the GenericMenu
component's props (e.g., tighten prop generics or typings), mention that this is
a non-runtime change, and keep the changeset type as 'patch' for package
'@rocket.chat/ui-client' so readers immediately know which component and package
the change affects.

TheRazorbill and others added 6 commits February 17, 2026 09:20
- Add explicit ReactElement type for button prop
- Remove unnecessary 'as any' cast in cloneElement call
- TypeScript now knows button is safe to clone without type assertion

Without explicit button?: ReactElement, TypeScript would infer button as
ReactNode from MenuV2 props spread, making cloneElement unsafe. This explicit
type makes the code type-safe without needing 'as any'.
@TheRazorbill TheRazorbill force-pushed the fix/improve-generic-menu-typing branch from 673b84f to 3016926 Compare February 17, 2026 12:20
@TheRazorbill TheRazorbill requested review from a team as code owners February 17, 2026 12:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.67%. Comparing base (afaabea) to head (fca705d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #38594   +/-   ##
========================================
  Coverage    70.67%   70.67%           
========================================
  Files         3191     3191           
  Lines       112963   112963           
  Branches     20451    20456    +5     
========================================
  Hits         79832    79832           
+ Misses       31085    31082    -3     
- Partials      2046     2049    +3     
Flag Coverage Δ
unit 71.29% <66.66%> (ø)

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.

@TheRazorbill
Copy link
Copy Markdown
Contributor Author

Hi team 👋
Just bumping this PR to check if it could get triaged when possible.
Happy to make any adjustments if needed. Thanks!

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.

GenericMenu: Improve type safety by removing unsafe casts

4 participants