refactor: close connections when the ws is not ready

This commit is contained in:
Mauricio Siu
2024-10-05 17:17:46 -06:00
parent 06b58e6495
commit 8397de0dca
4 changed files with 88 additions and 37 deletions

View File

@@ -21,6 +21,7 @@ export const ShowDeployment = ({ logPath, open, onClose, serverId }: Props) => {
useEffect(() => {
if (!open || !logPath) return;
setData("");
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
const wsUrl = `${protocol}//${window.location.host}/listen-deployment?logPath=${logPath}${serverId ? `&serverId=${serverId}` : ""}`;
@@ -61,13 +62,14 @@ export const ShowDeployment = ({ logPath, open, onClose, serverId }: Props) => {
open={open}
onOpenChange={(e) => {
onClose();
if (!e) setData("");
if (!e) {
setData("");
}
if (!e && wsRef.current) {
if (wsRef.current) {
if (wsRef.current.readyState === WebSocket.OPEN) {
wsRef.current.close();
}
setData("");
}
}}
>