@@ -431,10 +431,16 @@ const parsedQuery = computed<ParsedQuery>(() => {
431431const validatedSuggestions = ref <ValidatedSuggestion []>([])
432432const suggestionsLoading = shallowRef (false )
433433
434+ /** Counter to discard stale async results when query changes rapidly */
435+ let suggestionRequestId = 0
436+
434437/** Validate suggestions (check org/user existence) */
435438async function validateSuggestionsImpl(parsed : ParsedQuery ) {
439+ const requestId = ++ suggestionRequestId
440+
436441 if (! parsed .type || ! parsed .name ) {
437442 validatedSuggestions .value = []
443+ suggestionsLoading .value = false
438444 return
439445 }
440446
@@ -444,11 +450,13 @@ async function validateSuggestionsImpl(parsed: ParsedQuery) {
444450 try {
445451 if (parsed .type === ' user' ) {
446452 const exists = await checkUserExists (parsed .name )
453+ if (requestId !== suggestionRequestId ) return
447454 if (exists ) {
448455 suggestions .push ({ type: ' user' , name: parsed .name , exists: true })
449456 }
450457 } else if (parsed .type === ' org' ) {
451458 const exists = await checkOrgExists (parsed .name )
459+ if (requestId !== suggestionRequestId ) return
452460 if (exists ) {
453461 suggestions .push ({ type: ' org' , name: parsed .name , exists: true })
454462 }
@@ -458,6 +466,7 @@ async function validateSuggestionsImpl(parsed: ParsedQuery) {
458466 checkOrgExists (parsed .name ),
459467 checkUserExists (parsed .name ),
460468 ])
469+ if (requestId !== suggestionRequestId ) return
461470 // Org first (more common)
462471 if (orgExists ) {
463472 suggestions .push ({ type: ' org' , name: parsed .name , exists: true })
@@ -467,10 +476,15 @@ async function validateSuggestionsImpl(parsed: ParsedQuery) {
467476 }
468477 }
469478 } finally {
470- suggestionsLoading .value = false
479+ // Only clear loading if this is still the active request
480+ if (requestId === suggestionRequestId ) {
481+ suggestionsLoading .value = false
482+ }
471483 }
472484
473- validatedSuggestions .value = suggestions
485+ if (requestId === suggestionRequestId ) {
486+ validatedSuggestions .value = suggestions
487+ }
474488}
475489
476490// Debounce lightly for npm (extra API calls are slower), skip debounce for Algolia (fast)
0 commit comments