Skip to content

feat: Optimize search requests with AbortController - #209

Merged
amrbashir merged 1 commit into
tauri-apps:devfrom
tony140407:feat/optimize-search-requests
May 6, 2026
Merged

amrbashir merged 1 commit into
tauri-apps:devfrom
tony140407:feat/optimize-search-requests

Conversation

@tony140407

Copy link
Copy Markdown
Contributor

🎯 Motivation

Currently, when users type quickly in the search box, multiple API requests
are sent simultaneously. This can cause:

  • Race conditions where stale responses override newer results
  • Unnecessary load on the Meilisearch server
  • Poor user experience with flickering results

🔧 Changes

  • Add AbortController to cancel previous search requests when a new one starts
  • Pass signal to the Meilisearch SDK search method (3rd parameter)
  • Handle AbortError gracefully without showing error states
  • Clean up ongoing requests when component unmounts
  • Fix incorrect onReset() calls in error handlers that could cancel active requests

✅ Testing

Tested with:

  • Network throttling (Slow 3G) to verify old requests are properly cancelled
  • Rapid typing to confirm no race conditions occur
  • Chrome DevTools Network tab shows "cancelled" status for aborted requests

📸 Screenshots

截圖 2025-12-29 上午11 33 02

Happy to make any adjustments based on feedback! 😊

@amrbashir amrbashir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologoies for the late reply, I left a few comments. Could you also add a change file in .changes directory similar to this one https://github.com/tauri-apps/meilisearch-docsearch/blob/e5c670756e46f1f785b9c7a694eb337f5f4ce690/.changes/check-composition-event.md?plain=1

Comment thread src/DocSearchModal.tsx Outdated
Comment thread src/DocSearchModal.tsx Outdated
Comment thread src/DocSearchModal.tsx Outdated
Comment thread src/DocSearchModal.tsx
@tony140407
tony140407 force-pushed the feat/optimize-search-requests branch from 0ec6d9a to e9b4b30 Compare May 6, 2026 03:03
@tony140407
tony140407 force-pushed the feat/optimize-search-requests branch from e9b4b30 to eadf364 Compare May 6, 2026 03:14
@tony140407

Copy link
Copy Markdown
Contributor Author

@amrbashir Thanks for the review! I've addressed all the feedback:

  • Added changelog in .changes/
  • Collapsed the abort check to a single line
  • Split into resetState(screenState) (pure UI reset) and onReset() (abort + reset) — kept the onReset name since it's passed as a prop to DocSearchModalSearchBox
  • resetState is used in .catch() / .then() where the request already completed
  • Restored the error reset for the !res case to avoid leaving the UI in a loading state

Ready for another look when you have a chance.

@amrbashir
amrbashir merged commit 496e63e into tauri-apps:dev May 6, 2026
4 checks passed
@amrbashir

Copy link
Copy Markdown
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants