mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-21 03:32:09 +08:00
fix(react): avoid redundant DNS and proxy updates (#8543)
This commit is contained in:
@@ -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 = () => {
|
||||
>
|
||||
<TabButton
|
||||
isActive={activeTab === 'system'}
|
||||
onClick={() => handleTabChange('system')}
|
||||
onClick={handleSystemTabClick}
|
||||
icon={ComputerRounded}
|
||||
label={t('settings.sections.system.toggles.systemProxy')}
|
||||
hasIndicator={systemProxyIndicator}
|
||||
/>
|
||||
<TabButton
|
||||
isActive={activeTab === 'tun'}
|
||||
onClick={() => handleTabChange('tun')}
|
||||
onClick={handleTunTabClick}
|
||||
icon={TroubleshootRounded}
|
||||
label={t('settings.sections.system.toggles.tunMode')}
|
||||
hasIndicator={enable_tun_mode! && isTunModeAvailable}
|
||||
|
||||
@@ -586,20 +586,10 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
? 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 (
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user