mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 02:42:12 +08:00
perf(log): reuse the empty logs fallback identity
A fresh [] fallback gave the subscription hook's refresh callback and snapshot effect a new identity on every render while logs streamed; the empty list is now a shared module constant.
This commit is contained in:
@@ -12,6 +12,9 @@ const FLUSH_DELAY_MS = 50
|
||||
type LogType = ILogItem['type']
|
||||
|
||||
const DEFAULT_LOG_TYPES: LogType[] = ['debug', 'info', 'warning', 'error']
|
||||
// Shared empty fallback: a fresh [] would give `refresh` a new identity on
|
||||
// every render and re-run the snapshot effect while logs stream.
|
||||
const EMPTY_LOGS: ILogItem[] = []
|
||||
const LOG_LEVEL_FILTERS: Record<LogLevel, LogType[]> = {
|
||||
DEBUG: DEFAULT_LOG_TYPES,
|
||||
INFO: ['info', 'warning', 'error'],
|
||||
@@ -55,7 +58,7 @@ export const useLogData = () => {
|
||||
|
||||
const { response, refresh, setData } = useMihomoWsSubscription<ILogItem[]>({
|
||||
subscriptionKey: enableLog ? 'getClashLog' : null,
|
||||
fallbackData: [],
|
||||
fallbackData: EMPTY_LOGS,
|
||||
connect: () => MihomoWebSocket.connect_logs(logLevel),
|
||||
setupHandlers: ({ next, scheduleReconnect, isMounted }) => {
|
||||
let flushTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
Reference in New Issue
Block a user