Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(navbar): normalize return type of useSearchItems and remove incorrect SubscriptionWithRoom annotation#39260

Open
Agarwalchetan wants to merge 6 commits intoRocketChat:developfrom
Agarwalchetan:fix/use-search-items-return-type
Open

fix(navbar): normalize return type of useSearchItems and remove incorrect SubscriptionWithRoom annotation#39260
Agarwalchetan wants to merge 6 commits intoRocketChat:developfrom
Agarwalchetan:fix/use-search-items-return-type

Conversation

@Agarwalchetan
Copy link
Contributor

@Agarwalchetan Agarwalchetan commented Mar 2, 2026

fix #39259

The file already contains an explicit note acknowledging the problem:

// FIXME: the return type is UTTERLY wrong, but I'm not sure what it should be

This PR fixes the incorrect return type of the useSearchItems hook.

Previously, the hook was typed as:

UseQueryResult<SubscriptionWithRoom[] | undefined, Error>

However, its queryFn returned a mixed shape:

  • Local SubscriptionWithRoom[]
  • Server spotlight results (users + public channels) mapped into a lighter object

This made the declared return type inaccurate and misleading.


What This PR Does

1). Introduces SearchRenderableItem

A normalized interface that represents both:

  • Local subscriptions
  • Spotlight users and public channels

Key decisions:

  • Required badge fields from ISubscription (unread, userMentions, groupMentions) are guaranteed.
  • Spotlight results default these numeric values to 0, preserving correct badge behavior.
  • u is required to satisfy RoomIcon structural typing.

This avoids unsafe unions and keeps UI consumers simple.


2). Normalizes Data Inside queryFn

  • Spotlight users (t: 'd') receive a real u object from the server result.
  • Spotlight rooms (t: 'c') receive a minimal stub u object.

Safety verification:

Server-side audit confirms that includeInRoomSearch() only returns true for public channels (t: 'c'). Spotlight rooms are guaranteed to never be DMs, meaning the stub u will never reach isDirectMessageRoom() logic paths.


3). Updates Consumer Prop Types

Updated:

  • NavBarSearchRow
  • NavBarSearchItemWithData
  • NavBarSearchUserRow

All now accept SearchRenderableItem.

Explicit casts to SubscriptionWithRoom are used only at specific call sites (useUnreadDisplay, RoomIcon, SidebarItemBadges) where structural compatibility is guaranteed and verified.

No UI logic or behavior was changed.


Verification

  • Ran tsc --noEmit --skipLibCheck — all type errors related to this area are resolved.
  • ESLint passes cleanly.
  • No behavioral changes observed.
  • Server-side spotlight invariants audited to ensure runtime safety.

Result

  • Removes incorrect return type.
  • Avoids unsafe unions.
  • Preserves strict typing.
  • Maintains UI behavior.
  • Keeps normalization logic contained to the hook.

This change improves correctness and maintainability without introducing runtime risk.

Summary by CodeRabbit

  • Refactor

    • Standardized the search result item shape across navbar search and updated components to consume the unified format.
  • Bug Fixes / Improvements

    • More reliable distinction between user and room results, improving rendering accuracy.
    • Stabilized avatars, unread counts and badges in search results for a smoother, more consistent UI experience.

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 Agarwalchetan requested a review from a team as a code owner March 2, 2026 20:47
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 2, 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

changeset-bot bot commented Mar 2, 2026

⚠️ No Changeset found

Latest commit: 7a89c62

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Walkthrough

Replaces the prior SubscriptionWithRoom return/prop types with a new SearchRenderableItem type: useSearchItems now returns SearchRenderableItem[], and three navbar search components accept SearchRenderableItem props with small rendering/type adjustments.

Changes

Cohort / File(s) Summary
Hook & type definition
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
Added exported SearchRenderableItem type; changed useSearchItems return type to UseQueryResult<SearchRenderableItem[], Error>; refactored mapping (roomMap/userMap) to build unified SearchRenderableItem objects (includes u, unread, userMentions, groupMentions) and updated queryFn typing.
NavBar search components
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemWithData.tsx, apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx, apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsx
Updated prop types to accept SearchRenderableItem (imported from hook). NavBarSearchRow uses room.isUserResult to choose NavBarSearchUserRow vs NavBarSearchItemWithData. Components cast items back to SubscriptionWithRoom where required for existing utilities (Unread, RoomIcon, SidebarItemBadges).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: normalizing the return type of useSearchItems and removing incorrect SubscriptionWithRoom annotation on the hook.
Linked Issues check ✅ Passed The PR fully addresses issue #39259 by introducing SearchRenderableItem type, updating useSearchItems return type, and updating consumer components to use the accurate type while maintaining type-safety.
Out of Scope Changes check ✅ Passed All changes are directly scoped to correcting the useSearchItems return type and updating related consumer components; no unrelated modifications detected.
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
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 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.

Copy link
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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7367e3b and 7efcd12.

📒 Files selected for processing (4)
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemWithData.tsx
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsx
  • apps/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.tsx
  • apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
  • apps/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.tsx
  • 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/NavBarSearchUserRow.tsx
  • 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: 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 SearchRenderableItem and defaulting unread counters to 0 is 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 room to SearchRenderableItem here correctly aligns this component with useSearchItems.

apps/meteor/client/navbar/NavBarSearch/NavBarSearchUserRow.tsx (1)

7-13: This type update is aligned and safe.

NavBarSearchUserRow now consuming SearchRenderableItem matches 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
Copy link
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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7efcd12 and 38f15ea.

📒 Files selected for processing (2)
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchRow.tsx
  • apps/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.ts
  • apps/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 queryFn now consistently returns SearchRenderableItem[], and userMap/roomMap enforce 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.isUserResult is 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.
Copy link
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)
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)

21-21: Tighten t from string to subscription room-type for stricter safety.

Using string here 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

📥 Commits

Reviewing files that changed from the base of the PR and between 38f15ea and 7a89c62.

📒 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, and u) cleanly resolves the previous return-type mismatch and keeps consumers simpler.


79-83: Good normalization in queryFn and spotlight mappers.

queryFn now consistently returns SearchRenderableItem[], and both userMap/roomMap provide the required defaults, which makes downstream typing predictable.

Also applies to: 98-134

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.

Incorrect Return Type in useSearchItems Hook

1 participant