From 4ec3a9bf4cefa4615869a0f6bea1373defe173b5 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Mon, 29 Jun 2026 06:03:51 +0800 Subject: [PATCH] fix: defer provider queries on startup --- src/components/proxy/provider-button.tsx | 6 +++++- src/providers/app-data-provider.tsx | 2 ++ src/services/query-client.ts | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/proxy/provider-button.tsx b/src/components/proxy/provider-button.tsx index e3ac500b1..8f067ed26 100644 --- a/src/components/proxy/provider-button.tsx +++ b/src/components/proxy/provider-button.tsx @@ -18,7 +18,7 @@ import { } from '@mui/material' import { useLockFn } from 'ahooks' import dayjs from 'dayjs' -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { updateProxyProvider } from 'tauri-plugin-mihomo-api' @@ -52,6 +52,10 @@ export const ProviderButton = () => { const { refreshProxy, refreshProxyProviders } = useAppRefreshers() const [updating, setUpdating] = useState>({}) + useEffect(() => { + refreshProxyProviders().catch(() => {}) + }, [refreshProxyProviders]) + // 检查是否有提供者 const hasProviders = Object.keys(proxyProviders || {}).length > 0 diff --git a/src/providers/app-data-provider.tsx b/src/providers/app-data-provider.tsx index 3df291a93..4ccb883f1 100644 --- a/src/providers/app-data-provider.tsx +++ b/src/providers/app-data-provider.tsx @@ -79,12 +79,14 @@ export const AppDataProvider = ({ queryKey: ['getProxyProviders'], queryFn: calcuProxyProviders, ...TQ_MIHOMO, + revalidateOnMount: false, }) const { data: ruleProviders, refetch: _refetchRuleProviders } = useQuery({ queryKey: ['getRuleProviders'], queryFn: getRuleProviders, ...TQ_MIHOMO, + revalidateOnMount: false, }) const { data: rulesData, refetch: _refetchRules } = useQuery({ diff --git a/src/services/query-client.ts b/src/services/query-client.ts index 8b72bdf5a..21c0b9795 100644 --- a/src/services/query-client.ts +++ b/src/services/query-client.ts @@ -18,6 +18,7 @@ type QueryOptions = { retryDelay?: number | ((attempt: number) => number) refetchInterval?: number | false refetchIntervalInBackground?: boolean + revalidateOnMount?: boolean refetchOnWindowFocus?: boolean refetchOnReconnect?: boolean } @@ -110,6 +111,7 @@ export function useQuery(options: QueryOptions): QueryResult { retryDelay, refetchInterval, refetchIntervalInBackground, + revalidateOnMount, refetchOnWindowFocus, refetchOnReconnect, staleTime, @@ -148,6 +150,7 @@ export function useQuery(options: QueryOptions): QueryResult { }, interval) }, revalidateOnFocus: refetchOnWindowFocus, + revalidateOnMount, revalidateOnReconnect: refetchOnReconnect, refreshInterval: refetchInterval || 0, refreshWhenHidden: refetchIntervalInBackground ?? false,