fix websocket error reporting

This commit is contained in:
Evan Almloff committed 2022-06-09 09:36:28 -05:00
1 parent b480579169
commit 017d269ca8
2 files changed
+12 -12

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ desktop = ["dioxus-desktop"]
router = ["dioxus-router"] router = ["dioxus-router"]
tui = ["dioxus-tui"] tui = ["dioxus-tui"]
liveview = ["dioxus-liveview"] 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"] native-core = ["dioxus-native-core", "dioxus-native-core-macro"]
+11 -11
View File
@@ -237,7 +237,7 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
}; };
let url = format!( let url = format!(
"{protocol} //{}/_dioxus/hot_reload", "{protocol}//{}/_dioxus/hot_reload",
window.location().host().unwrap() window.location().host().unwrap()
); );
@@ -252,8 +252,9 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
}) as Box<dyn FnMut(MessageEvent)>); }) as Box<dyn FnMut(MessageEvent)>);
ws.set_onmessage(Some(cl.as_ref().unchecked_ref())); 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 { struct WebErrorHandler {
sender: UnboundedSender<Error>, sender: UnboundedSender<Error>,
@@ -269,17 +270,16 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
sender: error_channel_sender, sender: error_channel_sender,
}); });
RSX_CONTEXT.provide_scheduler_channel(dom.get_scheduler_channel());
// forward stream to the websocket // forward stream to the websocket
dom.base_scope().spawn_forever(async move { dom.base_scope().spawn_forever(async move {
error_channel_receiver while let Some(err) = error_channel_receiver.next().await {
.for_each(|err| { if let Error::RecompileRequiredError(err) = err {
if let Error::RecompileRequiredError(err) = err { ws.send_with_str(serde_json::to_string(&err).unwrap().as_str())
ws.send_with_str(serde_json::to_string(&err).unwrap().as_str()) .unwrap();
.unwrap(); }
} }
futures_util::future::ready(())
})
.await;
}); });
} }