Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/autoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export default function autoComplete(config) {
maxResults: 5,
};
this.resultItem = { tag: "li" };
// Request ID counter to detect and discard stale async responses
this._requestId = 0;
// Set all Configuration options
configure(this);
// Stage API methods
Expand Down
4 changes: 4 additions & 0 deletions src/services/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export default async function (ctx, q) {

// Validate trigger condition
if (condition) {
// Track this request to detect stale responses
const requestId = ++ctx._requestId;
// Get from source
await getData(ctx, queryVal);
// Discard if a newer request has been made since this one started
if (ctx._requestId !== requestId) return;
// Check if data fetch failed
if (ctx.feedback instanceof Error) return;
// Find matching results to the query
Expand Down