From 856a64dd18c0dbca75509785673b4eda85db5542 Mon Sep 17 00:00:00 2001 From: BakerNet Date: Fri, 23 Aug 2024 18:02:02 -0700 Subject: [PATCH] fix error when cleanup happens after reconnect attempt is on timeout --- src/use_websocket.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/use_websocket.rs b/src/use_websocket.rs index 30bd122..e7e420c 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -302,7 +302,11 @@ where { let reconnect_ref: StoredValue>> = store_value(None); reconnect_ref.set_value({ + let unmounted = Rc::clone(&unmounted); + Some(Rc::new(move || { + let unmounted = Rc::clone(&unmounted); + if !manually_closed_ref.get_value() && !reconnect_limit.is_exceeded_by(reconnect_times_ref.get_value()) && ws_ref @@ -312,6 +316,9 @@ where reconnect_timer_ref.set_value( set_timeout_with_handle( move || { + if unmounted.get() { + return; + } if let Some(connect) = connect_ref.get_value() { connect(); reconnect_times_ref.update_value(|current| *current += 1);