import type { DefaultError, UseQueryReturnType } from '@tanstack/vue-query' import type { Ref } from 'vue' import { computed } from 'vue' /** Subset of {@link UseQueryReturnType} passed to {@link useReadyState}. */ export type ReadyStateQuery = Pick< UseQueryReturnType, 'isLoading' | 'data' > /** * Returns true while a query is loading for the FIRST time (no cached data yet). * * Excludes background refetches and refetch-on-window-focus by design — those * have `isLoading === false` once data exists in the cache, so `ReadyTransition` * stays open and the loading bar stays silent. * * Pair with ``. */ export function useReadyState( query: ReadyStateQuery, ): Readonly> { return computed(() => query.isLoading.value && query.data.value === undefined) }