fix: throttle WebSocket subscriptions to prevent UI freeze on profile switch (#6683) (#6686)

Add leading-edge throttle to useMihomoWsSubscription, reduce SWR retry
aggressiveness, and increase WebSocket reconnect delay to prevent event
storms when switching profiles under poor network conditions.
This commit is contained in:
Tunglies
2026-04-02 13:22:30 +00:00
committed by GitHub
parent 3714f0c4c8
commit 824bcc77eb
5 changed files with 61 additions and 12 deletions
+4 -8
View File
@@ -81,6 +81,7 @@ export const useConnectionData = () => {
buildSubscriptKey: (date) => `getClashConnection-${date}`,
fallbackData: initConnData,
connect: () => MihomoWebSocket.connect_connections(),
throttleMs: 16,
setupHandlers: ({ next, scheduleReconnect }) => ({
handleMessage: (data) => {
if (data.startsWith('Websocket error')) {
@@ -89,14 +90,9 @@ export const useConnectionData = () => {
return
}
try {
const parsed = JSON.parse(data) as IConnections
next(null, (old = initConnData) =>
mergeConnectionSnapshot(parsed, old),
)
} catch (error) {
next(error)
}
next(null, (old = initConnData) =>
mergeConnectionSnapshot(JSON.parse(data) as IConnections, old),
)
},
}),
})