diff --git a/src/components/proxy/proxy-group-tools.tsx b/src/components/proxy/proxy-group-tools.tsx index c9da9bcc1..64c224556 100644 --- a/src/components/proxy/proxy-group-tools.tsx +++ b/src/components/proxy/proxy-group-tools.tsx @@ -31,9 +31,9 @@ interface Props { url?: string groupName: string headState: HeadState - onLocation: () => void - onCheckDelay: () => void - onHeadState: (val: Partial) => void + onLocation: (groupName: string) => void + onCheckDelay: (groupName: string) => void + onHeadState: (groupName: string, val: Partial) => void } export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { @@ -76,7 +76,7 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { // 因此对写入 headState 的动作做防抖,避免每输入一个字符就过滤一次。 const { run: applyFilter, flush: flushFilter } = useDebounceFn( (state: SearchState) => { - onHeadState({ + onHeadState(groupName, { filterText: state.text, filterMatchCase: state.matchCase, filterMatchWholeWord: state.matchWholeWord, @@ -125,7 +125,7 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { e.preventDefault() e.stopPropagation() }} - onChange={(e) => onHeadState({ testUrl: e.target.value })} + onChange={(e) => onHeadState(groupName, { testUrl: e.target.value })} sx={{ flex: '1 1 auto', input: { py: 0.65, px: 1 } }} /> )} @@ -155,8 +155,8 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { e.stopPropagation() if (!headState.open) // eslint-disable-next-line @eslint-react/dom-no-flush-sync - flushSync(() => onHeadState({ open: true })) - onLocation() + flushSync(() => onHeadState(groupName, { open: true })) + onLocation(groupName) }} > @@ -171,16 +171,16 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { e.stopPropagation() if (!headState.open) // eslint-disable-next-line @eslint-react/dom-no-flush-sync - flushSync(() => onHeadState({ open: true })) + flushSync(() => onHeadState(groupName, { open: true })) // Remind the user that it is custom test url if (testUrl?.trim() && textState !== 'filter') { - onHeadState({ textState: 'url' }) + onHeadState(groupName, { textState: 'url' }) } if (testUrl?.trim() && !isValidUrl(testUrl)) { showNotice.warning('proxies.feedback.warnings.invalidTestUrl') return } - onCheckDelay() + onCheckDelay(groupName) }} > @@ -201,8 +201,8 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { e.stopPropagation() if (!headState.open) // eslint-disable-next-line @eslint-react/dom-no-flush-sync - flushSync(() => onHeadState({ open: true })) - onHeadState({ + flushSync(() => onHeadState(groupName, { open: true })) + onHeadState(groupName, { sortType: ((sortType + 1) % 3) as ProxySortType, }) }} @@ -219,7 +219,7 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { onClick={(e) => { e.preventDefault() e.stopPropagation() - onHeadState({ + onHeadState(groupName, { textState: textState === 'url' ? null : 'url', }) setTimeout(() => inputRef.current?.focus()) @@ -245,8 +245,8 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { e.stopPropagation() if (!headState.open) // eslint-disable-next-line @eslint-react/dom-no-flush-sync - flushSync(() => onHeadState({ open: true })) - onHeadState({ showType: !showType }) + flushSync(() => onHeadState(groupName, { open: true })) + onHeadState(groupName, { showType: !showType }) }} > {showType ? ( @@ -265,8 +265,10 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) { e.stopPropagation() if (!headState.open && textState !== 'filter') // eslint-disable-next-line @eslint-react/dom-no-flush-sync - flushSync(() => onHeadState({ open: true })) - onHeadState({ textState: textState === 'filter' ? null : 'filter' }) + flushSync(() => onHeadState(groupName, { open: true })) + onHeadState(groupName, { + textState: textState === 'filter' ? null : 'filter', + }) setTimeout(() => inputRef.current?.focus()) }} > diff --git a/src/components/proxy/proxy-head.tsx b/src/components/proxy/proxy-head.tsx index 99574b36a..23e507682 100644 --- a/src/components/proxy/proxy-head.tsx +++ b/src/components/proxy/proxy-head.tsx @@ -30,9 +30,9 @@ interface Props { url?: string groupName: string headState: HeadState - onLocation: () => void - onCheckDelay: () => void - onHeadState: (val: Partial) => void + onLocation: (groupName: string) => void + onCheckDelay: (groupName: string) => void + onHeadState: (groupName: string, val: Partial) => void } const defaultSx: SxProps = {} @@ -81,7 +81,7 @@ export const ProxyHead = ({ size="small" color="inherit" title={t('proxies.page.tooltips.locate')} - onClick={onLocation} + onClick={() => onLocation(groupName)} > @@ -95,13 +95,13 @@ export const ProxyHead = ({ // Remind the user that it is custom test url if (testUrl?.trim() && textState !== 'filter') { debugLog(`[ProxyHead] 使用自定义测试URL: ${testUrl}`) - onHeadState({ textState: 'url' }) + onHeadState(groupName, { textState: 'url' }) } if (testUrl?.trim() && !isValidUrl(testUrl)) { showNotice.warning('proxies.feedback.warnings.invalidTestUrl') return } - onCheckDelay() + onCheckDelay(groupName) }} > @@ -118,7 +118,9 @@ export const ProxyHead = ({ ][sortType] } onClick={() => - onHeadState({ sortType: ((sortType + 1) % 3) as ProxySortType }) + onHeadState(groupName, { + sortType: ((sortType + 1) % 3) as ProxySortType, + }) } > {sortType !== 1 && sortType !== 2 && } @@ -131,7 +133,9 @@ export const ProxyHead = ({ color="inherit" title={t('proxies.page.tooltips.delayCheckUrl')} onClick={() => - onHeadState({ textState: textState === 'url' ? null : 'url' }) + onHeadState(groupName, { + textState: textState === 'url' ? null : 'url', + }) } > {textState === 'url' ? ( @@ -149,7 +153,7 @@ export const ProxyHead = ({ ? t('proxies.page.tooltips.showBasic') : t('proxies.page.tooltips.showDetail') } - onClick={() => onHeadState({ showType: !showType })} + onClick={() => onHeadState(groupName, { showType: !showType })} > {showType ? : } @@ -159,7 +163,9 @@ export const ProxyHead = ({ color="inherit" title={t('proxies.page.tooltips.filter')} onClick={() => - onHeadState({ textState: textState === 'filter' ? null : 'filter' }) + onHeadState(groupName, { + textState: textState === 'filter' ? null : 'filter', + }) } > {textState === 'filter' ? : } @@ -176,7 +182,7 @@ export const ProxyHead = ({ useRegularExpression: filterUseRegularExpression, }} onSearch={(_, state) => - onHeadState({ + onHeadState(groupName, { filterText: state.text, filterMatchCase: state.matchCase, filterMatchWholeWord: state.matchWholeWord, @@ -197,7 +203,7 @@ export const ProxyHead = ({ size="small" variant="outlined" placeholder={t('proxies.page.placeholders.delayCheckUrl')} - onChange={(e) => onHeadState({ testUrl: e.target.value })} + onChange={(e) => onHeadState(groupName, { testUrl: e.target.value })} sx={{ ml: 0.5, flex: '1 1 auto', input: { py: 0.65, px: 1 } }} /> )} diff --git a/src/components/proxy/proxy-render.tsx b/src/components/proxy/proxy-render.tsx index 6fb01d6b6..09cdb6f3d 100644 --- a/src/components/proxy/proxy-render.tsx +++ b/src/components/proxy/proxy-render.tsx @@ -33,7 +33,7 @@ interface RenderProps { item: IRenderItem stickyed?: boolean isChainMode?: boolean - onLocation: (group: IRenderItem['group']) => void + onLocation: (groupName: string) => void onCheckAll: (groupName: string) => void onHeadState: (groupName: string, patch: Partial) => void onChangeProxy: ( @@ -179,9 +179,9 @@ const ProxyGroupHeader = (props: RenderProps) => { url={group.testUrl!} groupName={group.name} headState={headState!} - onLocation={() => onLocation(group)} - onCheckDelay={() => onCheckAll(group.name)} - onHeadState={(p) => onHeadState(group.name, p)} + onLocation={onLocation} + onCheckDelay={onCheckAll} + onHeadState={onHeadState} /> {!toolsOnLeft && proxyCount} @@ -270,9 +270,9 @@ export const ProxyRender = memo(function ProxyRender(props: RenderProps) { url={group.testUrl!} groupName={group.name} headState={headState!} - onLocation={() => onLocation(group)} - onCheckDelay={() => onCheckAll(group.name)} - onHeadState={(p) => onHeadState(group.name, p)} + onLocation={onLocation} + onCheckDelay={onCheckAll} + onHeadState={onHeadState} /> ) } diff --git a/src/hooks/use-proxy-delay-state.ts b/src/hooks/use-proxy-delay-state.ts index 612b33d24..e600dd41d 100644 --- a/src/hooks/use-proxy-delay-state.ts +++ b/src/hooks/use-proxy-delay-state.ts @@ -61,7 +61,7 @@ export function useProxyDelayState( } const cachedUpdate = delayManager.getDelayUpdate(name, groupName) if (cachedUpdate) { - setDelayState({ ...cachedUpdate }) + setDelayState(cachedUpdate) return } diff --git a/src/services/delay.ts b/src/services/delay.ts index 565d0fd7b..7b56acbde 100644 --- a/src/services/delay.ts +++ b/src/services/delay.ts @@ -237,7 +237,9 @@ class DelayManager { return undefined } - return { ...entry } + // Entries are replaced, never mutated, so the cached object is shared + // directly; readers treat it as immutable. + return entry } getDelay(name: string, group: string) {