fix: global data not warming up correctly after hydration
This commit is contained in:
@@ -22,8 +22,8 @@ export const useAgents = () => {
|
||||
initPromise: Promise<void> | null;
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
if (state.initPromise) return;
|
||||
const init = (): Promise<void> => {
|
||||
if (state.initPromise) return state.initPromise;
|
||||
|
||||
state.initPromise = (async () => {
|
||||
const query = triplit.query('agents')
|
||||
@@ -32,10 +32,13 @@ export const useAgents = () => {
|
||||
|
||||
const { results } = await useQuery('agents', triplit, query)
|
||||
watch(results, (newAgents) => {
|
||||
console.log("newAgents", newAgents);
|
||||
state.list.value = newAgents as unknown as Agent[] || [];
|
||||
if (newAgents && newAgents.length > 0) {
|
||||
state.list.value = newAgents as unknown as Agent[];
|
||||
}
|
||||
}, { immediate: true, flush: 'sync' });
|
||||
})();
|
||||
|
||||
return state.initPromise;
|
||||
};
|
||||
|
||||
const getAgent = (id: MaybeRef<string>) => {
|
||||
|
||||
@@ -29,17 +29,21 @@ export const useModels = () => {
|
||||
initPromise: Promise<void> | null;
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
if (state.initPromise) return;
|
||||
const init = (): Promise<void> => {
|
||||
if (state.initPromise) return state.initPromise;
|
||||
|
||||
state.initPromise = (async () => {
|
||||
const query = triplit.query('providers').Include('models');
|
||||
|
||||
const { results } = await useQuery('providers', triplit, query)
|
||||
watch(results, (newProviders) => {
|
||||
state.providers.value = newProviders as unknown as ProviderWithModels[] || [];
|
||||
if (newProviders && newProviders.length > 0) {
|
||||
state.providers.value = newProviders as unknown as ProviderWithModels[];
|
||||
}
|
||||
}, { immediate: true, flush: 'sync' });
|
||||
})();
|
||||
|
||||
return state.initPromise;
|
||||
};
|
||||
|
||||
const allModels = computed<ModelWithProvider[]>(() => {
|
||||
|
||||
@@ -33,7 +33,7 @@ export const useUserSettings = () => {
|
||||
|
||||
const state = nuxtApp._userSettingsState as UserSettingsState;
|
||||
|
||||
const init = () => {
|
||||
const init = (): Promise<void> => {
|
||||
if (state.initPromise) return state.initPromise;
|
||||
|
||||
state.initPromise = (async () => {
|
||||
|
||||
Reference in New Issue
Block a user