fix: await concurrent calls to load() in settingStore and workflowStore

- Return early if already loaded (isReady/isSyncReady)
- Use VueUse `until()` to await in-progress loading instead of returning undefined
- Ensures all callers properly wait for initialization to complete

Amp-Thread-ID: https://ampcode.com/threads/T-019bfdee-7166-76c3-8c5f-473717a9148b
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-01-26 21:30:45 -08:00
parent b11eb7e045
commit 69efc65e77
2 changed files with 18 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import { retry } from 'es-toolkit'
import _ from 'es-toolkit/compat'
import { useAsyncState } from '@vueuse/core'
import { until, useAsyncState } from '@vueuse/core'
import { defineStore } from 'pinia'
import { compare, valid } from 'semver'
import { ref } from 'vue'
@@ -71,10 +71,15 @@ export const useSettingStore = defineStore('setting', () => {
{ immediate: false }
)
async function load() {
if (!isReady.value && !isLoading.value) {
return loadSettingValues()
async function load(): Promise<void> {
if (isReady.value) return
if (isLoading.value) {
await until(isLoading).toBe(false)
return
}
await loadSettingValues()
}
/**

View File

@@ -1,5 +1,5 @@
import _ from 'es-toolkit/compat'
import { useAsyncState } from '@vueuse/core'
import { until, useAsyncState } from '@vueuse/core'
import { defineStore } from 'pinia'
import { computed, markRaw, ref, shallowRef, watch } from 'vue'
import type { Raw } from 'vue'
@@ -558,10 +558,15 @@ export const useWorkflowStore = defineStore('workflow', () => {
return executeSyncWorkflows(0, dir)
}
async function loadWorkflows() {
if (!isSyncReady.value && !isSyncLoading.value) {
return syncWorkflows()
async function loadWorkflows(): Promise<void> {
if (isSyncReady.value) return
if (isSyncLoading.value) {
await until(isSyncLoading).toBe(false)
return
}
await syncWorkflows()
}
const bookmarkStore = useWorkflowBookmarkStore()