mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 02:42:12 +08:00
fix(sysproxy): read the live verge config in the toggle drain loop
The drain loop captured the render-time verge snapshot, so a config revalidation landing mid-loop left later iterations deciding connection closing and rollback with stale values. The confirmed-state seed and the in-loop auto-close check now read through a latest ref.
This commit is contained in:
@@ -48,10 +48,14 @@ export const useSystemProxyState = () => {
|
||||
// Coalesce rapid clicks so only the latest requested state is applied.
|
||||
const pendingRef = useRef<boolean | null>(null)
|
||||
const busyRef = useRef(false)
|
||||
// The drain loop outlives the render it started in; reading the config
|
||||
// through a ref keeps mid-loop revalidations visible to later iterations.
|
||||
const vergeRef = useRef(verge)
|
||||
vergeRef.current = verge
|
||||
|
||||
const toggleSystemProxy = async (enabled: boolean) => {
|
||||
// Roll failed optimistic writes back to the latest confirmed state.
|
||||
let confirmed = verge?.enable_system_proxy ?? false
|
||||
let confirmed = vergeRef.current?.enable_system_proxy ?? false
|
||||
mutateVerge((prev) =>
|
||||
prev ? { ...prev, enable_system_proxy: enabled } : prev,
|
||||
)
|
||||
@@ -69,7 +73,7 @@ export const useSystemProxyState = () => {
|
||||
errorNotice: false,
|
||||
})
|
||||
confirmed = target
|
||||
if (!target && verge?.auto_close_connection) {
|
||||
if (!target && vergeRef.current?.auto_close_connection) {
|
||||
await mutate(() => closeAllConnections(), {
|
||||
id: 'close-all-connections',
|
||||
errorNotice: false,
|
||||
|
||||
Reference in New Issue
Block a user