From 1105eedeb69d42cb847983801251384595adab26 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Tue, 3 Nov 2026 12:58:43 +0000 Subject: [PATCH] fix(react): avoid redundant DNS and proxy updates (#8543) --- src/components/home/proxy-tun-card.tsx | 19 ++++++++++++------- src/components/setting/mods/dns-viewer.tsx | 18 ++++-------------- src/hooks/use-proxy-delay-state.ts | 7 ++++++- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/components/home/proxy-tun-card.tsx b/src/components/home/proxy-tun-card.tsx index f460fd1de..a9dfc1412 100644 --- a/src/components/home/proxy-tun-card.tsx +++ b/src/components/home/proxy-tun-card.tsx @@ -14,7 +14,7 @@ import { useTheme, Fade, } from '@mui/material' -import { useState, useMemo, memo, FC } from 'react' +import { useState, useMemo, useCallback, memo, FC } from 'react' import { useTranslation } from 'react-i18next' import ProxyControlSwitches from '@/components/shared/proxy-control-switches' @@ -152,10 +152,15 @@ export const ProxyTunCard: FC = () => { showNotice.error(err) } - const handleTabChange = (tab: string) => { - setActiveTab(tab) - localStorage.setItem(LOCAL_STORAGE_TAB_KEY, tab) - } + const handleSystemTabClick = useCallback(() => { + setActiveTab('system') + localStorage.setItem(LOCAL_STORAGE_TAB_KEY, 'system') + }, []) + + const handleTunTabClick = useCallback(() => { + setActiveTab('tun') + localStorage.setItem(LOCAL_STORAGE_TAB_KEY, 'tun') + }, []) const tabDescription = useMemo(() => { if (activeTab === 'system') { @@ -191,14 +196,14 @@ export const ProxyTunCard: FC = () => { > handleTabChange('system')} + onClick={handleSystemTabClick} icon={ComputerRounded} label={t('settings.sections.system.toggles.systemProxy')} hasIndicator={systemProxyIndicator} /> handleTabChange('tun')} + onClick={handleTunTabClick} icon={TroubleshootRounded} label={t('settings.sections.system.toggles.tunMode')} hasIndicator={enable_tun_mode! && isTunModeAvailable} diff --git a/src/components/setting/mods/dns-viewer.tsx b/src/components/setting/mods/dns-viewer.tsx index 1ab82ba7f..71f01217e 100644 --- a/src/components/setting/mods/dns-viewer.tsx +++ b/src/components/setting/mods/dns-viewer.tsx @@ -586,20 +586,10 @@ export function DnsViewer({ ref }: { ref?: Ref }) { ? event.target.checked : event.target.value - setValues((prev) => { - const newValues = { - ...prev, - [field]: value, - } - - if (visualization) { - setTimeout(() => { - updateYamlFromValues() - }, 0) - } - - return newValues - }) + setValues((prev) => ({ + ...prev, + [field]: value, + })) } return ( diff --git a/src/hooks/use-proxy-delay-state.ts b/src/hooks/use-proxy-delay-state.ts index f8a07f299..612b33d24 100644 --- a/src/hooks/use-proxy-delay-state.ts +++ b/src/hooks/use-proxy-delay-state.ts @@ -17,7 +17,12 @@ const PRESET_PROXY_NAMES = [ 'COMPATIBLE', ] -const identity = (_: DelayUpdate, next: DelayUpdate): DelayUpdate => next +const identity = (previous: DelayUpdate, next: DelayUpdate): DelayUpdate => + previous.delay === next.delay && + previous.elapsed === next.elapsed && + previous.updatedAt === next.updatedAt + ? previous + : next const INITIAL_DELAY: DelayUpdate = { delay: -1, updatedAt: 0 }