RocketChat / RocketChat/Rocket.Chat

Incorrect Return Type in `useSearchItems` Hook

Open
#39,259 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

The useSearchItems hook in
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
has an incorrect return type annotation.

It is currently typed as:

UseQueryResult<SubscriptionWithRoom[] | undefined, Error>

However, the queryFn does not consistently return SubscriptionWithRoom[]. In addition to local subscriptions (from useUserSubscriptions), it also appends spotlight results returned from the server (spotlight Meteor method). These spotlight results are mapped into a different shape that does not strictly match SubscriptionWithRoom.

This creates a mismatch between the declared return type and the actual runtime data structure. As a result, TypeScript is misled about the true shape of the returned data, which can lead to unsafe assumptions in downstream components and reduced maintainability.

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

Expected behavior

The return type of useSearchItems should accurately reflect the real structure of the data returned by queryFn, covering both local subscriptions and spotlight results in a type-safe and maintainable way.


Actual behavior

The hook is typed as returning SubscriptionWithRoom[] | undefined, even though it actually returns a mixed, differently shaped array when spotlight results are included.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts and inspect the queryFn, useUserSubscriptions data, and the spotlight Meteor method results. Compare the local and spotlight shapes with SubscriptionWithRoom, then define a return type that accurately covers both sources. Done means the annotation matches the runtime array without misleading downstream TypeScript code.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.