🐛(search) fix double request and flickering on search#596
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe mailbox provider's search handling was refactored: debounced global query resets were removed, the threads query key now uses a fixed Changes
Sequence Diagram(s)sequenceDiagram
participant UI as Mailbox Component
participant QC as QueryClient
participant Sel as ThreadSelection
UI->>UI: detect search param change
alt leaving search mode
UI->>QC: removeQueries(['threads', mailboxId, 'search'], exact:true)
QC-->>UI: queries removed
UI->>Sel: unselectThread()
Sel-->>UI: thread unselected
else search term changed (still searching)
UI->>QC: resetQueries(['threads', mailboxId, 'search'])
QC-->>UI: queries reset/refetched
UI->>Sel: unselectThread()
Sel-->>UI: thread unselected
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/frontend/src/features/providers/mailbox.tsx (1)
140-146: Centralize the thread query-key builder.
src/frontend/src/features/layouts/components/thread-view/components/thread-summary/index.tsx:1-80now duplicates this samesearch ? ['threads', mailboxId, 'search'] : ['threads', mailboxId, searchParams.toString()]branching. Pulling it into one helper would keep future cache-key fixes from drifting between the provider and the thread summary view.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/frontend/src/features/providers/mailbox.tsx` around lines 140 - 146, Duplicate logic for building the threads query key exists in the mailbox provider (threadQueryKey in the useMemo using selectedMailbox?.id and searchParams) and in thread-summary; extract that branching into a single helper (e.g., buildThreadQueryKey or getThreadQueryKey) that accepts mailboxId and searchParams and returns either ['threads', mailboxId, 'search'] or ['threads', mailboxId, searchParams.toString()], then replace the inline useMemo logic in the provider (threadQueryKey) and the component in src/frontend/src/features/layouts/components/thread-view/components/thread-summary to call the shared helper so both places use the same canonical cache-key builder.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/frontend/src/features/providers/mailbox.tsx`:
- Around line 597-603: The effect only resets queries when the search term
changes but doesn't clear the cached search results when exiting search mode;
update the useEffect that references previousSearchParams, searchParams and
queryClient so that when previousSearchParams?.get('search') is truthy and
searchParams.get('search') is falsy (search -> null transition) you call
queryClient.removeQueries({ queryKey: ['threads', selectedMailbox?.id, 'search']
}) to purge the cached search results for the current mailbox ID (use the same
selectedMailbox?.id key used elsewhere).
---
Nitpick comments:
In `@src/frontend/src/features/providers/mailbox.tsx`:
- Around line 140-146: Duplicate logic for building the threads query key exists
in the mailbox provider (threadQueryKey in the useMemo using selectedMailbox?.id
and searchParams) and in thread-summary; extract that branching into a single
helper (e.g., buildThreadQueryKey or getThreadQueryKey) that accepts mailboxId
and searchParams and returns either ['threads', mailboxId, 'search'] or
['threads', mailboxId, searchParams.toString()], then replace the inline useMemo
logic in the provider (threadQueryKey) and the component in
src/frontend/src/features/layouts/components/thread-view/components/thread-summary
to call the shared helper so both places use the same canonical cache-key
builder.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1605adb1-2274-40dd-8cd1-bf6dbf963268
📒 Files selected for processing (1)
src/frontend/src/features/providers/mailbox.tsx
e620ce7 to
a575d4f
Compare
Purpose
The search queryKey included searchParams.toString(), creating a new React Query entry per search term (triggering fetch #1). Meanwhile, resetSearchQueryDebounced cleared the active query 500ms later (triggering fetch #2 + flicker).
Summary by CodeRabbit
Release Notes