diff --git a/src/use_websocket.rs b/src/use_websocket.rs index e7e420c..44a8b4d 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -344,17 +344,19 @@ where } let web_socket = { - protocols.as_ref().map_or_else( - || WebSocket::new(&url).unwrap_throw(), - |protocols| { - let array = protocols - .iter() - .map(|p| JsValue::from(p.clone())) - .collect::(); - WebSocket::new_with_str_sequence(&url, &JsValue::from(&array)) - .unwrap_throw() - }, - ) + protocols.with_untracked(|protocols| { + protocols.as_ref().map_or_else( + || WebSocket::new(&url).unwrap_throw(), + |protocols| { + let array = protocols + .iter() + .map(|p| JsValue::from(p.clone())) + .collect::(); + WebSocket::new_with_str_sequence(&url, &JsValue::from(&array)) + .unwrap_throw() + }, + ) + }) }; web_socket.set_binary_type(BinaryType::Arraybuffer); set_ready_state.set(ConnectionReadyState::Connecting); @@ -650,7 +652,8 @@ where /// Defaults to `true`. immediate: bool, /// Sub protocols. See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket#protocols). - protocols: Option>, + #[builder(into)] + protocols: MaybeSignal>>, } impl UseWebSocketOptions {