diff --git a/src/components/rule/provider-button.tsx b/src/components/rule/provider-button.tsx index c394e6569..d0f0eb100 100644 --- a/src/components/rule/provider-button.tsx +++ b/src/components/rule/provider-button.tsx @@ -17,7 +17,7 @@ import { } from '@mui/material' import { useLockFn } from 'ahooks' import dayjs from 'dayjs' -import { useState } from 'react' +import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { updateRuleProvider } from 'tauri-plugin-mihomo-api' @@ -42,6 +42,11 @@ export const ProviderButton = () => { const { t } = useTranslation() const [open, setOpen] = useState(false) const { ruleProviders } = useRulesData() + + const sortedProviderEntries = useMemo( + () => Object.entries(ruleProviders || {}).sort(), + [ruleProviders], + ) const { refreshRules, refreshRuleProviders } = useAppRefreshers() const [updating, setUpdating] = useState>({}) @@ -166,121 +171,119 @@ export const ProviderButton = () => { - {Object.entries(ruleProviders || {}) - .sort() - .map(([key, item]) => { - const provider = item - const time = dayjs(provider.updatedAt) - const isUpdating = updating[key] + {sortedProviderEntries.map(([key, item]) => { + const provider = item + const time = dayjs(provider.updatedAt) + const isUpdating = updating[key] - return ( - { - const bgcolor = mode === 'light' ? '#ffffff' : '#24252f' - const hoverColor = - mode === 'light' - ? alpha(primary.main, 0.1) - : alpha(primary.main, 0.2) + return ( + { + const bgcolor = mode === 'light' ? '#ffffff' : '#24252f' + const hoverColor = + mode === 'light' + ? alpha(primary.main, 0.1) + : alpha(primary.main, 0.2) - return { - backgroundColor: bgcolor, - '&:hover': { - backgroundColor: hoverColor, - borderColor: alpha(primary.main, 0.3), - }, - } - }, - ]} - > - - - {key} - - {provider.ruleCount} - - - - - {t('shared.labels.updateAt')}: - {time.fromNow()} - - + return { + backgroundColor: bgcolor, + '&:hover': { + backgroundColor: hoverColor, + borderColor: alpha(primary.main, 0.3), + }, } - secondary={ - - - {typeof provider.vehicleType === 'string' - ? provider.vehicleType - : provider.vehicleType.Unknown} - - - {typeof provider.behavior === 'string' - ? provider.behavior - : provider.behavior.Unknown} - - - } - /> - - - updateProvider(key)} - disabled={isUpdating} - aria-label={t('rules.page.provider.actions.update')} + }, + ]} + > + - - - - - ) - })} + + {key} + + {provider.ruleCount} + + + + + {t('shared.labels.updateAt')}: + {time.fromNow()} + + + } + secondary={ + + + {typeof provider.vehicleType === 'string' + ? provider.vehicleType + : provider.vehicleType.Unknown} + + + {typeof provider.behavior === 'string' + ? provider.behavior + : provider.behavior.Unknown} + + + } + /> + + + updateProvider(key)} + disabled={isUpdating} + aria-label={t('rules.page.provider.actions.update')} + sx={{ + animation: isUpdating + ? 'spin 1s linear infinite' + : 'none', + '@keyframes spin': { + '0%': { transform: 'rotate(0deg)' }, + '100%': { transform: 'rotate(360deg)' }, + }, + }} + title={t('rules.page.provider.actions.update')} + > + + + + + ) + })} diff --git a/src/components/setting/mods/tun-viewer.tsx b/src/components/setting/mods/tun-viewer.tsx index 69953c037..54addaadc 100644 --- a/src/components/setting/mods/tun-viewer.tsx +++ b/src/components/setting/mods/tun-viewer.tsx @@ -9,7 +9,7 @@ import { } from '@mui/material' import { useLockFn } from 'ahooks' import type { Ref } from 'react' -import { useState } from 'react' +import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { @@ -58,8 +58,9 @@ export function TunViewer({ ref }: { ref?: Ref }) { dnsMode: '', }) - const routeExcludeAddressItems = splitRouteExcludeAddress( - values.routeExcludeAddress, + const routeExcludeAddressItems = useMemo( + () => splitRouteExcludeAddress(values.routeExcludeAddress), + [values.routeExcludeAddress], ) const routeExcludeAddressError = values.autoRoute && diff --git a/src/hooks/use-group-delays.ts b/src/hooks/use-group-delays.ts index d2ef763e4..3871a2c27 100644 --- a/src/hooks/use-group-delays.ts +++ b/src/hooks/use-group-delays.ts @@ -1,4 +1,4 @@ -import { useCallback, useSyncExternalStore } from 'react' +import { useCallback, useMemo, useSyncExternalStore } from 'react' import delayManager, { type DelaySnapshot } from '@/services/delay' import type { ResolvedProxyMember } from '@/types/proxy-view' @@ -32,7 +32,7 @@ export const useGroupsDelays = ( groups: readonly string[], ): ReadonlyMap => { // Group membership must remain unambiguous when names contain spaces. - const groupKey = JSON.stringify(groups) + const groupKey = useMemo(() => JSON.stringify(groups), [groups]) const subscribe = useCallback( (onSettle: () => void) => {