mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-04 22:52:23 +08:00
fix: frontend memory leaks — Monaco dispose, TQ cache eviction, useEffect cleanup
- Dispose Monaco editor instances on dialog close to prevent cycle leak - Replace gcTime: Infinity with finite TTLs and evict orphaned subscription queryKeys - Add missing useEffect cleanup for timers, move setTimeout out of useMemo
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import yaml from 'js-yaml'
|
||||
import type { editor } from 'monaco-editor'
|
||||
import type { Ref } from 'react'
|
||||
import {
|
||||
useCallback,
|
||||
@@ -189,6 +190,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [visualization, setVisualization] = useState(true)
|
||||
const skipYamlSyncRef = useRef(false)
|
||||
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null)
|
||||
const [values, setValues] = useState<{
|
||||
enable: boolean
|
||||
listen: string
|
||||
@@ -453,6 +455,13 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
}
|
||||
}, [visualization])
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
editorRef.current?.dispose()
|
||||
editorRef.current = null
|
||||
}
|
||||
}, [])
|
||||
|
||||
const initDnsConfig = useCallback(async () => {
|
||||
try {
|
||||
const dnsConfigExists = await invoke<boolean>(
|
||||
@@ -1057,6 +1066,9 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
value={yamlContent}
|
||||
theme={themeMode === 'light' ? 'light' : 'vs-dark'}
|
||||
className="flex-grow"
|
||||
onMount={(editorInstance) => {
|
||||
editorRef.current = editorInstance
|
||||
}}
|
||||
options={{
|
||||
tabSize: 2,
|
||||
minimap: {
|
||||
|
||||
Reference in New Issue
Block a user