fix(repoList): prevent duplicate entries from concurrent loadMore calls

Add isLoading guard so concurrent fetches are rejected, and include
isLoading in canLoadMore so vInfiniteScroll waits before firing again.
This commit is contained in:
Julien Calixte
2026-04-27 10:33:31 +02:00
parent da4fada8a1
commit 74491a45a9

View File

@@ -9,6 +9,7 @@ const STALE_TIME_MS = 20 * 60 * 1000
const repos = ref<RepoBase[]>([]) const repos = ref<RepoBase[]>([])
const isReady = ref(false) const isReady = ref(false)
const isLoading = ref(false)
const hasCredentialError = ref(false) const hasCredentialError = ref(false)
const currentPage = ref(0) const currentPage = ref(0)
const totalCount = ref(0) const totalCount = ref(0)
@@ -22,6 +23,8 @@ export const useRepos = () => {
isReady.value = true isReady.value = true
return return
} }
if (isLoading.value) return
isLoading.value = true
try { try {
const octokit = await getOctokit() const octokit = await getOctokit()
const nextPage = currentPage.value + 1 const nextPage = currentPage.value + 1
@@ -53,10 +56,13 @@ export const useRepos = () => {
} }
} finally { } finally {
isReady.value = true isReady.value = true
isLoading.value = false
} }
} }
const canLoadMore = computed(() => repos.value.length < totalCount.value) const canLoadMore = computed(
() => !isLoading.value && repos.value.length < totalCount.value
)
const isStale = Date.now() - lastFetchedAt > STALE_TIME_MS const isStale = Date.now() - lastFetchedAt > STALE_TIME_MS
if (!isReady.value || isStale) { if (!isReady.value || isStale) {
@@ -65,6 +71,7 @@ export const useRepos = () => {
currentPage.value = 0 currentPage.value = 0
totalCount.value = 0 totalCount.value = 0
isReady.value = false isReady.value = false
isLoading.value = false
hasCredentialError.value = false hasCredentialError.value = false
} }
lastFetchedAt = Date.now() lastFetchedAt = Date.now()