refactor: improve type safety by removing as any casts in composer components#41566
refactor: improve type safety by removing as any casts in composer components#41566Rajkaran-122 wants to merge 1 commit into
Conversation
|
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 |
|
|
|
WalkthroughThe changes replace unsafe casts with explicit typing in marketplace code and add runtime validation for composer popup filters before slash-command lookup. ChangesMarketplace typing
Composer filter validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/views/marketplace/hooks/useInstallApp.tsx`:
- Around line 43-46: Update the useUpload mutation callback in useInstallApp to
handle UploadResult by rejecting when result.success is false and returning the
typed success payload, removing the unknown/type-unsafe casts. Define a separate
app-install/update endpoint result type in `@rocket.chat/rest-typings` and apply
it to the /apps and /apps/update contracts so useMutation receives the correct
typed response.
🪄 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 Plus
Run ID: 3a13445c-6ac7-40db-bd6c-d3e1187b0630
📒 Files selected for processing (3)
apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsxapps/meteor/client/views/marketplace/hooks/useInstallApp.tsxapps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.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/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsxapps/meteor/client/views/marketplace/hooks/useInstallApp.tsxapps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
🧠 Learnings (6)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.
Applied to files:
apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsxapps/meteor/client/views/marketplace/hooks/useInstallApp.tsx
📚 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/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsxapps/meteor/client/views/marketplace/hooks/useInstallApp.tsxapps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.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/room/composer/hooks/useComposerBoxPopupQueries.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/room/composer/hooks/useComposerBoxPopupQueries.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 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/client/views/room/composer/hooks/useComposerBoxPopupQueries.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/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
🔇 Additional comments (2)
apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts (1)
18-26: LGTM!apps/meteor/client/views/marketplace/components/CategoryFilter/CategoryDropDownList.tsx (1)
17-17: LGTM!
| return uploadAppEndpoint(fileData) as unknown as Promise<{ app: App }>; | ||
| }, | ||
|
|
||
| onSuccess: (data: { app: App }) => { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Locate target file and upload helper:"
fd -a 'useInstallApp\.tsx|useUpload|uploadAppEndpoint|apps/update|apps' . | sed 's#^\./##' | head -200
echo
echo "Target file excerpt:"
sed -n '1,140p' apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx 2>/dev/null || true
echo
echo "Search uploadAppEndpoint definitions/imports:"
rg -n "uploadAppEndpoint|useUpload|\\bapps/.+upload|useMutation\\(.*upload|Upload\\(" apps -g '*.{ts,tsx,js}' --glob '!**/node_modules/**' --glob '!**/.git/**' | head -300Repository: RocketChat/Rocket.Chat
Length of output: 13792
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "useUpload hook:"
sed -n '1,220p' packages/ui-contexts/src/hooks/useUpload.ts
echo
echo "upload-related market-place/test references:"
rg -n "POST /apps|/apps\\b|/apps/update|AppUpload|uploadApp|app:|upload" apps/meteor/app/apps apps/meteor/public apps/meteor/server/api apps/meteor/tests apps/meteor/client/views/marketplace packages rest-typings --glob '*.{ts,tsx,js,json}' | head -300
echo
echo "apps REST API files:"
fd -a 'apps.*\.(ts|tsx|js)$|.*apps.*\.(ts|tsx|js)$' apps/meteor/server/api apps/meteor/app/apps --ignore-case | head -200Repository: RocketChat/Rocket.Chat
Length of output: 38964
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "useEndpointUploadMutation type context:"
sed -n '1,120p' apps/meteor/client/hooks/useEndpointUploadMutation.ts
echo
echo "API endpoint candidates that handle multipart app uploads:"
rg -n "POST|POST_API|api\\.v1\\.post|addRoute\\(['\"]apps|/apps|uploadApp|uploadUpdate|apps/update|AppClientUpload|uploadToEndpoint" apps/meteor/server/api apps/meteor/app apps/meteor/ee/server apps/meteor/client packages/ui-contexts src --glob '*.{ts,tsx,js}' | head -400
echo
echo "package ui-contexts contexts/type files:"
fd -a 'ServerContext\.ts|upload.*\.ts|api.*\.ts|Endpoint.*\.ts' packages/ui-contexts src --ignore-case | head -100Repository: RocketChat/Rocket.Chat
Length of output: 50378
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "ServerProvider upload/result helper context:"
sed -n '1,110p' apps/meteor/client/providers/ServerProvider.tsx
echo
echo "Focused search for APP upload endpoints:"
rg -n "POST_API|api\.v1\.post|addRoute\\(['\"]apps|apiServer|Router|install|private|upload|\\.update\\(|apps/update|/apps\\b" apps/meteor/server/api apps/meteor/app/apps --glob '*.{ts,tsx,js}' | head -250
echo
echo "REST typings app routes relevant to install/update:"
fd -a 'apps.*\.(ts|tsx|json)$|.*apps.*\.(ts|tsx|json)$' packages/rest-typings -i | while read -r f; do echo "--- $f"; rg -n "/apps|apps/update|private|install|upload" "$f" || true; doneRepository: RocketChat/Rocket.Chat
Length of output: 34549
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "REST typings package files:"
git ls-files packages/rest-typings | sed -n '1,200p'
echo
echo "Search for App upload schemas/endpoints in repos:"
rg -n "EndpointResult|OperationResult|POST::|apps/update|apps'\\b|/apps|upload.*App|App.*upload|app:.*upload|apps.private|apps.private|apps.private-create|private-app|private" packages/rest-typings src --glob '*.{ts,tsx,js,json}' | head -300 || true
echo
echo "Client tests/mocks around app upload response shape:"
rg -n "POST /api/apps|/api/apps|\\bapp:|response\\.|body\\.|success|\\.app|installLocalTestPackage|private-apps-upload" apps/meteor/tests apps/meteor/client/providers apps/meteor/tests/mocks packages/ui-contexts --glob '*.{ts,tsx,js}' | head -300Repository: RocketChat/Rocket.Chat
Length of output: 49201
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "REST typings apps relevant sections:"
sed -n '230,285p' packages/rest-typings/src/apps/index.ts
echo "--- OperationResult excerpt"
sed -n '190,220p' packages/rest-typings/src/index.ts
echo
echo "useEndpointUploadMutation implementation:"
sed -n '1,90p' apps/meteor/client/hooks/useEndpointUploadMutation.ts
echo
echo "Focused endpoint references for app package upload/update:"
rg -n "POST_API|api\.v1\.post|addRoute\\(['\"]apps|apiServer\\.post|apps/private|private-app|updateApp|installApp|AppClientOrchestrator|AppManager|update\\(|install\\(" apps/meteor/server/api apps/meteor/ee/server/apps apps/meteor/app/apps apps/meteor/client --glob '*.{ts,tsx,js}' | head -400Repository: RocketChat/Rocket.Chat
Length of output: 18157
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "REST typings apps route list around /apps/update:"
rg -n "/apps(update|private|update-app|updateApp|updateApp.*)|update" packages/rest-typings/src/apps/index.ts packages/rest-typings/src/help* packages/rest-typings/src -g '*.ts' | head -250
echo
echo "Server endpoint files that contain updateApp handler:"
rg -n "updateApp\\(|update\\(.*app|APP|app.*update|API\\.v1\\.post|Router|apps/update|update-app" apps/meteor/ee/server/apps apps/meteor/server/api apps/meteor/app/apps apps/meteor/client --glob '*.{ts,tsx,js,jsx}' | head -400
echo
echo "REST typings index imports listing app route file names:"
rg -n "from '.*/apps|from '../apps|from './apps" packages/rest-typings/src/index.ts packages/rest-typings/src/rest* packages/rest-typings/src/v1 packages/rest-typings/src/app packages/rest-typings/src -g '*.ts' | head -200Repository: RocketChat/Rocket.Chat
Length of output: 47065
Remove the type-unsafe endpoint casts.
useUpload always returns UploadResult, so useMutation should reject on !result.success and type the app-install/update endpoint result separately instead of widening through as unknown. Also add the update endpoint result type to @rocket.chat/rest-typings so /apps/update can share the same typed response contract as /apps.
🤖 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 `@apps/meteor/client/views/marketplace/hooks/useInstallApp.tsx` around lines 43
- 46, Update the useUpload mutation callback in useInstallApp to handle
UploadResult by rejecting when result.success is false and returning the typed
success payload, removing the unknown/type-unsafe casts. Define a separate
app-install/update endpoint result type in `@rocket.chat/rest-typings` and apply
it to the /apps and /apps/update contracts so useMutation receives the correct
typed response.
Source: Coding guidelines
Summary
This PR improves TypeScript hygiene by replacing unsafe
as anytype assertions with strict type guards and generic assertions across various client views.What Changed
as anyonfilterobject with a properhasCmdtype guard inuseComposerBoxPopupQueries.ts.as anyand casted toas unknown as Promise<{ app: App }>to strictly match the mutation'sonSuccesscallback inuseInstallApp.tsx.as anyspread property insideCategoryDropDownList.tsxby passing thelabelprop directly.Why
Overuse of
as anybreaks the reliability of the TypeScript compiler. This PR guarantees that these React components have robust, compile-time prop and variable validation.Testing
Checklist