mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-11-04 09:00:21 +00:00
fix: ws cleanup before unload
This commit is contained in:
1 parent
0a64cdc8c3
commit
4da870dd79
3 files changed
+12
-5
No files matched your search
@@ -106,8 +106,15 @@ export const WebSocketProvider: React.FC<WebSocketProviderProps> = ({ url, child
|
||||
useEffect(() => {
|
||||
connect()
|
||||
|
||||
// 添加页面卸载事件监听
|
||||
const handleBeforeUnload = () => {
|
||||
cleanup()
|
||||
}
|
||||
window.addEventListener('beforeunload', handleBeforeUnload)
|
||||
|
||||
return () => {
|
||||
cleanup()
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload)
|
||||
}
|
||||
}, [url])
|
||||
|
||||
|
||||
Reference in new issue
Block a user