From 017d269ca81508807c207f49ee33d97ab73b8c58 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 9 Jun 2022 09:36:28 -0500 Subject: [PATCH] fix websocket error reporting --- Cargo.toml | 2 +- packages/web/src/lib.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 172be5eea..7db59226c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ desktop = ["dioxus-desktop"] router = ["dioxus-router"] tui = ["dioxus-tui"] liveview = ["dioxus-liveview"] -hot_reload = ["dioxus-core-macro/hot_reload", "dioxus-rsx-interpreter", "dioxus-desktop?/hot_reload"] +hot_reload = ["dioxus-core-macro/hot_reload", "dioxus-rsx-interpreter", "dioxus-desktop?/hot_reload", "dioxus-web?/hot_reload"] native-core = ["dioxus-native-core", "dioxus-native-core-macro"] diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 3caac1b86..2e6ce4688 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -237,7 +237,7 @@ pub async fn run_with_props(root: Component, root_props: T }; let url = format!( - "{protocol} //{}/_dioxus/hot_reload", + "{protocol}//{}/_dioxus/hot_reload", window.location().host().unwrap() ); @@ -252,8 +252,9 @@ pub async fn run_with_props(root: Component, root_props: T }) as Box); ws.set_onmessage(Some(cl.as_ref().unchecked_ref())); + cl.forget(); - let (error_channel_sender, error_channel_receiver) = unbounded(); + let (error_channel_sender, mut error_channel_receiver) = unbounded(); struct WebErrorHandler { sender: UnboundedSender, @@ -269,17 +270,16 @@ pub async fn run_with_props(root: Component, root_props: T sender: error_channel_sender, }); + RSX_CONTEXT.provide_scheduler_channel(dom.get_scheduler_channel()); + // forward stream to the websocket dom.base_scope().spawn_forever(async move { - error_channel_receiver - .for_each(|err| { - if let Error::RecompileRequiredError(err) = err { - ws.send_with_str(serde_json::to_string(&err).unwrap().as_str()) - .unwrap(); - } - futures_util::future::ready(()) - }) - .await; + while let Some(err) = error_channel_receiver.next().await { + if let Error::RecompileRequiredError(err) = err { + ws.send_with_str(serde_json::to_string(&err).unwrap().as_str()) + .unwrap(); + } + } }); }