Merge pull request #5 from hamster1963/main

sync
This commit is contained in:
wood chen 2025-01-09 17:43:15 +08:00 committed by GitHub
commit f21a8cf844
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 5 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -24,8 +24,8 @@
"@radix-ui/react-separator": "^1.1.1",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-switch": "^1.1.2",
"@tanstack/react-query": "^5.62.15",
"@tanstack/react-query-devtools": "^5.62.15",
"@tanstack/react-query": "^5.63.0",
"@tanstack/react-query-devtools": "^5.63.0",
"@tanstack/react-table": "^8.20.6",
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
"@types/d3-geo": "^3.1.0",
@ -37,7 +37,7 @@
"dayjs": "^1.11.13",
"framer-motion": "^12.0.0-alpha.2",
"i18n-iso-countries": "^7.13.0",
"i18next": "^24.2.0",
"i18next": "^24.2.1",
"lucide-react": "^0.460.0",
"luxon": "^3.5.0",
"prettier-plugin-tailwindcss": "^0.6.9",
@ -53,7 +53,7 @@
"devDependencies": {
"@eslint/js": "^9.17.0",
"@types/node": "^22.10.5",
"@types/react": "^19.0.2",
"@types/react": "^19.0.4",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react-swc": "^3.7.2",
"autoprefixer": "^10.4.20",
@ -64,7 +64,7 @@
"postcss": "^8.4.49",
"tailwindcss": "^3.4.17",
"typescript": "~5.6.3",
"typescript-eslint": "^8.19.0",
"typescript-eslint": "^8.19.1",
"vite": "^6.0.7"
}
}

View File

@ -106,8 +106,29 @@ export const WebSocketProvider: React.FC<WebSocketProviderProps> = ({ url, child
useEffect(() => {
connect()
// 添加页面可见性变化监听
const handleVisibilityChange = () => {
if (document.hidden) {
// 页面隐藏时断开连接
cleanup()
} else {
// 页面可见时重新连接
connect()
}
}
// 添加页面卸载事件监听
const handleBeforeUnload = () => {
cleanup()
}
document.addEventListener("visibilitychange", handleVisibilityChange)
window.addEventListener("beforeunload", handleBeforeUnload)
return () => {
cleanup()
document.removeEventListener("visibilitychange", handleVisibilityChange)
window.removeEventListener("beforeunload", handleBeforeUnload)
}
}, [url])