Skip to content

fix: show faster spotlight results using cached subscriptions - #40965

Merged
ggazzo merged 6 commits into
developfrom
client-spotlight-use-subs
Jun 17, 2026
Merged

fix: show faster spotlight results using cached subscriptions#40965
ggazzo merged 6 commits into
developfrom
client-spotlight-use-subs

Conversation

@sampaiodiego

@sampaiodiego sampaiodiego commented Jun 15, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

The navbar search ("spotlight") used to show instant results from the client-side subscription cache (the user's joined rooms) while the server spotlight request resolved in the background. That fast-feedback behavior had been lost, and there was no visible "still loading" affordance.

Two problems defeated the original UX:

  1. Local results were not instant. NavBarSearchListbox debounced the filter text by 500ms and passed the debounced value into useSearchItems. Because the local subscription query (useUserSubscriptions) lived inside that hook, the cached results were delayed by the full 500ms too.
  2. No visible loading UI. The listbox only set aria-busy; nothing told a sighted user that more results were still arriving.

Video showing the results (bare in mind there is a 5s delay for backend response)

instant-spotlight-v3.mp4

What changed

  • useSearchItems — the local useUserSubscriptions query now runs against the immediate filter text, so joined rooms appear instantly. Only the /v1/spotlight request is debounced (500ms, keyed on the debounced term). Local + server results are merged reactively (in a useMemo, outside the query) so cached rooms render the moment the user types and server results fold in — deduped — once they arrive. The hook now returns an explicit { items, isLoading } shape (resolving the previous "return type is UTTERLY wrong" FIXME).
  • NavBarSearchListbox — passes the raw filter text (the hook now owns debouncing) and renders a few skeleton rows (NavBarSearchItemSkeleton) at the bottom of the list while the server request is in flight, so cached results stay visible above them and the loading state mimics the real result rows.

Accessibility & i18n

  • The skeleton rows are decorative: aria-hidden, no role="option" (so arrow-key navigation skips them), and tabIndex={-1} + pointer-events: none (not focusable, not clickable).
  • Loading is conveyed non-visually via aria-busy on the listbox plus a role="status" live region announcing the existing Loading translation key — no new user-facing strings were added.

Issue(s)

Steps to test or reproduce

  1. Sign in to an account that has joined several channels.
  2. Open the navbar search (Cmd/Ctrl+K) and type part of a joined channel's name.
  3. Expected: matching cached subscriptions appear immediately (well under 500ms), with skeleton rows at the bottom of the list.
  4. After the server responds, public channels you're not in fold in (deduped against the cached ones) and the skeletons disappear.
  5. Type a term that matches nothing locally or remotely → skeletons show during the fetch, then "Try entering a different search term".
  6. # prefix → channels only; @ prefix → users/DMs only (existing behavior preserved).

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added dedicated skeleton placeholders and a live “Loading” announcement during navbar search.
  • Bug Fixes
    • Improved search behavior to avoid stale matches while typing by reconciling local filtering with server results.
    • Enhanced deduping and prioritization of exact matches in the merged results.
    • Adjusted server fetching/loading state handling so results don’t flicker while requests are in flight.

Task: ARCH-2181

@dionisio-bot

dionisio-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7375939

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

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

useSearchItems is rewritten to debounce only the server spotlight call (500 ms) while computing local subscription matches immediately from the raw filterText, returning { items, isLoading } instead of a raw UseQueryResult. A new NavBarSearchItemSkeleton component renders loading placeholders, and ResultsLiveRegion is updated to announce loading state via a visually hidden live region.

Changes

NavBar Search: debounced server calls, skeleton loading UI

Layer / File(s) Summary
useSearchItems hook: debounced server + immediate local merge
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts
Return type changes to { items: SubscriptionWithRoom[]; isLoading: boolean }. Local rooms are matched immediately from filterText; debouncedName (500 ms) keys the React Query spotlight request and is conditionally enabled by localRooms.length < LIMIT. A new items memo deduplicates server results, filters stale matches against the current (non-debounced) filter, prioritizes exact results, and ignores server candidates when local results fill the limit. isLoading reflects isFetching combined with placeholder and undefined-state conditions.
Skeleton component and live-region loading announcements
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx, apps/meteor/client/components/ResultsLiveRegion.tsx
NavBarSearchItemSkeleton renders a SidebarV2Item with Skeleton avatar and title, marked aria-hidden, tabIndex={-1}, and pointerEvents: 'none'. ResultsLiveRegion adds an optional isLoading prop and refactors message computation: it announces the translated "Loading" string when isLoading is true, suppresses announcements when shouldAnnounce is false, and otherwise announces either "No results found" or a counted results message based on itemCount.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: displaying cached subscription results faster in the spotlight search feature using those cached subscriptions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.07%. Comparing base (928346f) to head (7375939).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #40965      +/-   ##
===========================================
- Coverage    70.11%   70.07%   -0.05%     
===========================================
  Files         3357     3358       +1     
  Lines       129542   129567      +25     
  Branches     22404    22477      +73     
===========================================
- Hits         90832    90795      -37     
- Misses       35420    35472      +52     
- Partials      3290     3300      +10     
Flag Coverage Δ
e2e 59.21% <97.05%> (-0.05%) ⬇️
e2e-api 46.21% <ø> (ø)
unit 70.03% <89.47%> (-0.06%) ⬇️

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.

@sampaiodiego
sampaiodiego force-pushed the client-spotlight-use-subs branch from 62f5622 to bc05cb6 Compare June 16, 2026 18:08
@sampaiodiego
sampaiodiego marked this pull request as ready for review June 16, 2026 21:11
@sampaiodiego
sampaiodiego requested a review from a team as a code owner June 16, 2026 21:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx (1)

3-6: ⚡ Quick win

Remove the implementation comment block.

This block should be removed to match repository JS/TS guideline expectations.

As per coding guidelines: **/*.{ts,tsx,js}: “Avoid code comments in the implementation.”

🤖 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/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx` around
lines 3 - 6, Remove the implementation comment block at the beginning of
NavBarSearchItemSkeleton.tsx that documents the placeholder row behavior. Delete
the multi-line comment (the four lines starting with "// Placeholder row
shown..." and ending with "// it out of reach of focus and mouse clicks. Loading
is conveyed via aria-busy.") as it violates the repository guideline to avoid
code comments in implementation for TypeScript and JavaScript files.

Source: Coding guidelines

apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts (1)

34-35: ⚡ Quick win

Remove inline implementation comments from the hook.

Please drop these explanatory comments from the implementation and keep the rationale in PR/docs instead.

As per coding guidelines: **/*.{ts,tsx,js}: “Avoid code comments in the implementation.”

Also applies to: 38-39, 59-63, 104-106, 114-115, 118-131

🤖 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/navbar/NavBarSearch/hooks/useSearchItems.ts` around lines
34 - 35, Remove all inline implementation comments from the useSearchItems hook
in apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts across
multiple locations (lines 34-35, 38-39, 59-63, 104-106, 114-115, and 118-131) as
they violate the coding guideline that prohibits code comments in
implementation. Delete the comment blocks at each of these locations, keeping
the functional code intact. The rationale for these implementation decisions
should be documented separately in PR descriptions or external documentation
rather than as inline comments in the code.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts`:
- Around line 34-35: Remove all inline implementation comments from the
useSearchItems hook in
apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts across multiple
locations (lines 34-35, 38-39, 59-63, 104-106, 114-115, and 118-131) as they
violate the coding guideline that prohibits code comments in implementation.
Delete the comment blocks at each of these locations, keeping the functional
code intact. The rationale for these implementation decisions should be
documented separately in PR descriptions or external documentation rather than
as inline comments in the code.

In `@apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx`:
- Around line 3-6: Remove the implementation comment block at the beginning of
NavBarSearchItemSkeleton.tsx that documents the placeholder row behavior. Delete
the multi-line comment (the four lines starting with "// Placeholder row
shown..." and ending with "// it out of reach of focus and mouse clicks. Loading
is conveyed via aria-busy.") as it violates the repository guideline to avoid
code comments in implementation for TypeScript and JavaScript files.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc4b8921-b2e6-40a1-af6a-b436a7ac604c

📥 Commits

Reviewing files that changed from the base of the PR and between fbf3672 and c6f4ad7.

📒 Files selected for processing (3)
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchListbox.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). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
🧰 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/NavBarSearchItemSkeleton.tsx
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchListbox.tsx
  • apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.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/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchListbox.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/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearchListbox.tsx
  • 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-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/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
🔇 Additional comments (3)
apps/meteor/client/navbar/NavBarSearch/NavBarSearchItemSkeleton.tsx (1)

7-20: LGTM!

apps/meteor/client/navbar/NavBarSearch/NavBarSearchListbox.tsx (2)

54-55: LGTM!

Also applies to: 57-67


31-31: Form defaults guarantee filterText is always initialized; no action needed.

filterText is initialized with defaultValues: { filterText: '' } in the parent form setup (line 24 of NavBarSearchInput.tsx). The watch() call in NavBarSearchListbox will always return this field with a string value (at minimum empty string), never undefined. The .match() call at line 21 of useSearchItems handles empty strings correctly.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/client/navbar/NavBarSearch/hooks/useSearchItems.ts Outdated
sampaiodiego and others added 6 commits June 16, 2026 22:48
The local subscription query lived inside useSearchItems but received the
500ms-debounced filter, so cached results were delayed just like the server
call. Run the local useUserSubscriptions query against the immediate filter
text and debounce only the /v1/spotlight request, then merge local + server
results reactively (outside the query) so joined rooms render instantly while
the server response loads. Returns an explicit { items, isLoading } shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pass the raw filter text to useSearchItems (the hook now owns debouncing) and
render an accessible Throbber at the bottom of the results while the server
spotlight request is in flight, so users see cached results immediately and
know more are still loading. The spinner is decorative (aria-hidden, not a
listbox option); loading is announced via aria-busy plus a role="status"
live region. Reuses the existing "Loading" i18n key.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sampaiodiego
sampaiodiego force-pushed the client-spotlight-use-subs branch from c6f4ad7 to 7375939 Compare June 17, 2026 01:48
@ggazzo ggazzo added this to the 8.6.0 milestone Jun 17, 2026
@ggazzo

ggazzo commented Jun 17, 2026

Copy link
Copy Markdown
Member

/jira ARCH-2167

@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Jun 17, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jun 17, 2026
@ggazzo
ggazzo merged commit 236eef2 into develop Jun 17, 2026
47 checks passed
@ggazzo
ggazzo deleted the client-spotlight-use-subs branch June 17, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants