Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default class Autocomplete extends Controller {
}
static uniqOptionId = 0

#latestFetchAt = null

connect() {
this.close()

Expand Down Expand Up @@ -197,7 +199,10 @@ export default class Autocomplete extends Controller {
const url = this.buildURL(query)
try {
this.element.dispatchEvent(new CustomEvent("loadstart"))
const currentFetchAt = new Date
const html = await this.doFetch(url)
if (this.#latestFetchAt && this.#latestFetchAt > currentFetchAt) return
this.#latestFetchAt = currentFetchAt
this.replaceResults(html)
this.element.dispatchEvent(new CustomEvent("load"))
this.element.dispatchEvent(new CustomEvent("loadend"))
Expand Down