fix(navbar): normalize return type of useSearchItems and remove incorrect SubscriptionWithRoom annotation#39260
Conversation
Define SearchRenderableItem — a normalized type covering both local SubscriptionWithRoom items and server spotlight results. This replaces the incorrect UseQueryResult<SubscriptionWithRoom[] | undefined, Error> annotation which did not match the actual data shape produced by the queryFn. Key design decisions: - SearchRenderableItem includes all required numeric badge fields (unread, userMentions, groupMentions) defaulting to 0 for spotlight results, keeping SidebarItemBadges and useUnreadDisplay structurally compatible. - spotlight users (t='d') receive a real u object from server data. - spotlight rooms are guaranteed to be public channels only (t='c') because the server's includeInRoomSearch() returns true only for the public room type — so the u stub is never accessed via isDirectMessageRoom path. - NavBarSearchRow, NavBarSearchItemWithData, NavBarSearchUserRow updated to use SearchRenderableItem instead of SubscriptionWithRoom.
Define SearchRenderableItem — a normalized type covering both local SubscriptionWithRoom items and spotlight server results. This replaces the incorrect UseQueryResult<SubscriptionWithRoom[] | undefined, Error> annotation which did not match the actual data shape produced by queryFn. Key design decisions: - All required numeric badge fields (unread, userMentions, groupMentions) default to 0 for spotlight results — keeping SidebarItemBadges and useUnreadDisplay compatible without changing those components. - Spotlight users (t=d) receive a real u object from server user data. - Spotlight rooms are guaranteed public channels only (t=c) because includeInRoomSearch() returns true only for public room type on server. - NavBarSearchRow, NavBarSearchItemWithData, NavBarSearchUserRow updated to use SearchRenderableItem instead of SubscriptionWithRoom.
…/Agarwalchetan/Rocket.Chat into fix/use-search-items-return-type
|
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 |
|
WalkthroughReplaces the prior Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx">
<violation number="1" location="apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx:10">
P2: After normalizing to `SearchRenderableItem`, the `!room.u` guard is no longer a valid discriminator, so spotlight DM user results can be rendered by the wrong row component.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx`:
- Line 10: The DM spotlight branch is unreachable because the code checks if
(room.t === 'd' && !room.u) but room is now SearchRenderableItem with u
required; remove the "!room.u" guard so DM rooms are matched by if (room.t ===
'd') and then explicitly detect spotlight users using the new mapping (e.g.,
inspect room.u?.spotlight or the room.s flag) to decide when to render
NavBarSearchUserRow; update NavBarSearchRow to route DM spotlight users to
NavBarSearchUserRow using that explicit spotlight check rather than relying on
absence of room.u.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemWithData.tsxapps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsxapps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsxapps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📜 Review details
⏰ 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 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/navbar/NavBarSearch/NavBarSearchUserRow.tsxapps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.tsapps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsxapps/meteor/client/navbar/NavBarSearch/NavBarSearchItemWithData.tsx
🧠 Learnings (8)
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsxapps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsxapps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2026-01-19T18:08:13.423Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38169
File: packages/ui-client/src/hooks/useGoToDirectMessage.ts:20-27
Timestamp: 2026-01-19T18:08:13.423Z
Learning: In React hooks, including custom hooks like useUserSubscriptionByName, must always be called unconditionally and in the same order on every render, per the Rules of Hooks. Passing empty strings or fallback values to hooks is the correct approach when dealing with potentially undefined values, rather than conditionally calling the hook based on whether the value exists.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').
Applied to files:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
📚 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:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
🧬 Code graph analysis (4)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsx (1)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
SearchRenderableItem(19-41)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
packages/core-typings/src/ISubscription.ts (1)
ISubscription(11-81)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx (1)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
SearchRenderableItem(19-41)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemWithData.tsx (3)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
SearchRenderableItem(19-41)apps/meteor/client/views/navigation/sidebar/hooks/useUnreadDisplay.ts (1)
useUnreadDisplay(6-10)packages/ui-contexts/src/index.ts (1)
SubscriptionWithRoom(112-112)
🔇 Additional comments (3)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
19-41: Type normalization in the hook looks solid.Unifying local subscriptions and spotlight results behind
SearchRenderableItemand defaulting unread counters to0is a good fix for the previous mismatched return type.Also applies to: 78-133
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemWithData.tsx (1)
7-15: Prop type migration is consistent with the new hook contract.Switching
roomtoSearchRenderableItemhere correctly aligns this component withuseSearchItems.apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsx (1)
7-13: This type update is aligned and safe.
NavBarSearchUserRownow consumingSearchRenderableItemmatches the new search data model consistently.
After normalizing spotlight results to SearchRenderableItem, we started
populating u for spotlight users (u: { _id, username, name }). This made
the old
oom.t === 'd' && !room.u guard in NavBarSearchRow always false,
causing spotlight DM user results to render as NavBarSearchItemWithData
(channel row) instead of NavBarSearchUserRow (user row).
Fix: add isUserResult?: boolean to SearchRenderableItem, set it true only
in userMap, and replace the guard with
oom.t === 'd' && room.isUserResult
— an unambiguous discriminator that correctly routes all cases:
- spotlight users: isUserResult=true -> NavBarSearchUserRow
- spotlight rooms: isUserResult=undefined -> NavBarSearchItemWithData
- local subscriptions: isUserResult=undefined -> NavBarSearchItemWithData
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts`:
- Around line 41-43: Remove the inline implementation comment block inside the
SearchRenderableItem definition: locate the comment text starting with "Explicit
discriminator: true only for spotlight user results." and the following two
lines explaining the replacement of `!room.u`. Delete these comment lines so
SearchRenderableItem contains only code and adheres to the repo's "avoid code
comments in the implementation" guideline.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsxapps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📜 Review details
⏰ 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 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/navbar/NavBarSearch/hooks/useSearchItems.tsapps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
🧠 Learnings (10)
📚 Learning: 2026-01-19T18:08:13.423Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38169
File: packages/ui-client/src/hooks/useGoToDirectMessage.ts:20-27
Timestamp: 2026-01-19T18:08:13.423Z
Learning: In React hooks, including custom hooks like useUserSubscriptionByName, must always be called unconditionally and in the same order on every render, per the Rules of Hooks. Passing empty strings or fallback values to hooks is the correct approach when dealing with potentially undefined values, rather than conditionally calling the hook based on whether the value exists.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').
Applied to files:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).
Applied to files:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
📚 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:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
🧬 Code graph analysis (2)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
packages/core-typings/src/ISubscription.ts (1)
ISubscription(11-81)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx (1)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
SearchRenderableItem(19-45)
🔇 Additional comments (2)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
82-137: Normalization and query return typing look correct.The
queryFnnow consistently returnsSearchRenderableItem[], anduserMap/roomMapenforce a unified renderable shape without unsafe unions.apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx (1)
7-10: Good update to explicit user-result discrimination.Switching from structural inference to
room.isUserResultis a cleaner and safer branch condition with the new normalized item type.Also applies to: 17-19
Removed commented-out code regarding user result discrimination.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
21-21: Tightentfromstringto subscription room-type for stricter safety.Using
stringhere weakens the benefit of the new normalized type and allows invalid room-type values to slip through type checks.Suggested diff
export type SearchRenderableItem = { _id: string; - t: string; + t: ISubscription['t']; name: string; rid?: string; @@ const roomMap = (room: { _id: string; name: string; - t: string; + t: ISubscription['t']; teamMain?: boolean; fname?: string; avatarETag?: string; uids?: string[]; }): SearchRenderableItem => ({Also applies to: 119-119
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts` at line 21, The property 't' typed as plain string in useSearchItems (the 't: string' declarations) should be tightened to the subscription room-type alias (e.g., SubscriptionRoomType or the project's RoomType union) to prevent invalid room-type values; update both occurrences (the one near the top and the one around the later use) to use the correct subscription room-type type and add the necessary import of that type at the top of the file (or reference the existing type export) so the compiler enforces valid room-type values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts`:
- Line 21: The property 't' typed as plain string in useSearchItems (the 't:
string' declarations) should be tightened to the subscription room-type alias
(e.g., SubscriptionRoomType or the project's RoomType union) to prevent invalid
room-type values; update both occurrences (the one near the top and the one
around the later use) to use the correct subscription room-type type and add the
necessary import of that type at the top of the file (or reference the existing
type export) so the compiler enforces valid room-type values.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📜 Review details
🧰 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/navbar/NavBarSearch/hooks/useSearchItems.ts
🧠 Learnings (9)
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to **/*.{ts,tsx,js} : Avoid code comments in the implementation
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2025-11-10T19:06:20.146Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37408
File: apps/meteor/client/views/admin/ABAC/useRoomAttributeOptions.tsx:53-69
Timestamp: 2025-11-10T19:06:20.146Z
Learning: In the Rocket.Chat repository, do not provide suggestions or recommendations about code sections marked with TODO comments. The maintainers have already identified these as future work and external reviewers lack the full context about implementation plans and timing.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2026-01-19T18:08:13.423Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38169
File: packages/ui-client/src/hooks/useGoToDirectMessage.ts:20-27
Timestamp: 2026-01-19T18:08:13.423Z
Learning: In React hooks, including custom hooks like useUserSubscriptionByName, must always be called unconditionally and in the same order on every render, per the Rules of Hooks. Passing empty strings or fallback values to hooks is the correct approach when dealing with potentially undefined values, rather than conditionally calling the hook based on whether the value exists.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.
Applied to files:
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/hooks/useSearchItems.ts
🧬 Code graph analysis (1)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)
packages/core-typings/src/ISubscription.ts (1)
ISubscription(11-81)
🔇 Additional comments (2)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (2)
19-42: Nice normalization of mixed search results into one renderable contract.This unified shape (including required
unread,userMentions,groupMentions, andu) cleanly resolves the previous return-type mismatch and keeps consumers simpler.
79-83: Good normalization inqueryFnand spotlight mappers.
queryFnnow consistently returnsSearchRenderableItem[], and bothuserMap/roomMapprovide the required defaults, which makes downstream typing predictable.Also applies to: 98-134
fix #39259
The file already contains an explicit note acknowledging the problem:
This PR fixes the incorrect return type of the
useSearchItemshook.Previously, the hook was typed as:
However, its
queryFnreturned a mixed shape:SubscriptionWithRoom[]This made the declared return type inaccurate and misleading.
What This PR Does
1). Introduces
SearchRenderableItemA normalized interface that represents both:
Key decisions:
ISubscription(unread,userMentions,groupMentions) are guaranteed.0, preserving correct badge behavior.uis required to satisfyRoomIconstructural typing.This avoids unsafe unions and keeps UI consumers simple.
2). Normalizes Data Inside
queryFnt: 'd') receive a realuobject from the server result.t: 'c') receive a minimal stubuobject.Safety verification:
Server-side audit confirms that
includeInRoomSearch()only returnstruefor public channels (t: 'c'). Spotlight rooms are guaranteed to never be DMs, meaning the stubuwill never reachisDirectMessageRoom()logic paths.3). Updates Consumer Prop Types
Updated:
NavBarSearchRowNavBarSearchItemWithDataNavBarSearchUserRowAll now accept
SearchRenderableItem.Explicit casts to
SubscriptionWithRoomare used only at specific call sites (useUnreadDisplay,RoomIcon,SidebarItemBadges) where structural compatibility is guaranteed and verified.No UI logic or behavior was changed.
Verification
tsc --noEmit --skipLibCheck— all type errors related to this area are resolved.Result
This change improves correctness and maintainability without introducing runtime risk.
Summary by CodeRabbit
Refactor
Bug Fixes / Improvements