Merge remote-tracking branch 'upstream/master' into pr/Demonthos/482
This commit is contained in:
commit
de3e2a48f8
4 files changed
+73
-46
No files matched your search
@@ -86,6 +86,8 @@ impl DesktopController {
|
|||||||
(serde_json::to_string(&err).unwrap() + "\n").as_bytes(),
|
(serde_json::to_string(&err).unwrap() + "\n").as_bytes(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
panic!("{}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::CodeLocation;
|
use crate::CodeLocation;
|
||||||
@@ -38,3 +40,18 @@ impl ParseError {
|
|||||||
ParseError { message, location }
|
ParseError { message, location }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::ParseError(error) => write!(
|
||||||
|
f,
|
||||||
|
"parse error:\n--> at {}:{}:{}\n\t{:?}\n",
|
||||||
|
error.location.file_path, error.location.line, error.location.column, error.message
|
||||||
|
),
|
||||||
|
Error::RecompileRequiredError(reason) => {
|
||||||
|
write!(f, "recompile required: {:?}\n", reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -150,6 +150,8 @@ impl RsxContext {
|
|||||||
fn report_error(&self, error: Error) {
|
fn report_error(&self, error: Error) {
|
||||||
if let Some(handler) = &self.data.write().unwrap().error_handler {
|
if let Some(handler) = &self.data.write().unwrap().error_handler {
|
||||||
handler.handle_error(error)
|
handler.handle_error(error)
|
||||||
|
} else {
|
||||||
|
panic!("no error handler set for this platform...\n{}", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+52
-46
@@ -62,6 +62,7 @@ use dioxus_core::prelude::Component;
|
|||||||
use dioxus_core::SchedulerMsg;
|
use dioxus_core::SchedulerMsg;
|
||||||
use dioxus_core::VirtualDom;
|
use dioxus_core::VirtualDom;
|
||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
|
use web_sys::console;
|
||||||
|
|
||||||
mod cache;
|
mod cache;
|
||||||
mod cfg;
|
mod cfg;
|
||||||
@@ -172,50 +173,6 @@ pub fn launch_with_props<T>(
|
|||||||
pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T, cfg: WebConfig) {
|
pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T, cfg: WebConfig) {
|
||||||
let mut dom = VirtualDom::new_with_props(root, root_props);
|
let mut dom = VirtualDom::new_with_props(root, root_props);
|
||||||
|
|
||||||
for s in crate::cache::BUILTIN_INTERNED_STRINGS {
|
|
||||||
wasm_bindgen::intern(s);
|
|
||||||
}
|
|
||||||
for s in &cfg.cached_strings {
|
|
||||||
wasm_bindgen::intern(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
let tasks = dom.get_scheduler_channel();
|
|
||||||
|
|
||||||
let sender_callback: Rc<dyn Fn(SchedulerMsg)> =
|
|
||||||
Rc::new(move |event| tasks.unbounded_send(event).unwrap());
|
|
||||||
|
|
||||||
let should_hydrate = cfg.hydrate;
|
|
||||||
|
|
||||||
let mut websys_dom = dom::WebsysDom::new(cfg, sender_callback);
|
|
||||||
|
|
||||||
log::trace!("rebuilding app");
|
|
||||||
|
|
||||||
if should_hydrate {
|
|
||||||
// todo: we need to split rebuild and initialize into two phases
|
|
||||||
// it's a waste to produce edits just to get the vdom loaded
|
|
||||||
let _ = dom.rebuild();
|
|
||||||
|
|
||||||
if let Err(err) = websys_dom.rehydrate(&dom) {
|
|
||||||
log::error!(
|
|
||||||
"Rehydration failed {:?}. Rebuild DOM into element from scratch",
|
|
||||||
&err
|
|
||||||
);
|
|
||||||
|
|
||||||
websys_dom.root.set_text_content(None);
|
|
||||||
|
|
||||||
// errrrr we should split rebuild into two phases
|
|
||||||
// one that initializes things and one that produces edits
|
|
||||||
let edits = dom.rebuild();
|
|
||||||
|
|
||||||
websys_dom.apply_edits(edits.edits);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let edits = dom.rebuild();
|
|
||||||
websys_dom.apply_edits(edits.edits);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut work_loop = ric_raf::RafLoop::new();
|
|
||||||
|
|
||||||
#[cfg(feature = "hot-reload")]
|
#[cfg(feature = "hot-reload")]
|
||||||
{
|
{
|
||||||
use dioxus_rsx_interpreter::error::Error;
|
use dioxus_rsx_interpreter::error::Error;
|
||||||
@@ -274,12 +231,61 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
|
|||||||
// forward stream to the websocket
|
// forward stream to the websocket
|
||||||
dom.base_scope().spawn_forever(async move {
|
dom.base_scope().spawn_forever(async move {
|
||||||
while let Some(err) = error_channel_receiver.next().await {
|
while let Some(err) = error_channel_receiver.next().await {
|
||||||
ws.send_with_str(serde_json::to_string(&err).unwrap().as_str())
|
if ws.ready_state() == WebSocket::OPEN {
|
||||||
.unwrap();
|
ws.send_with_str(serde_json::to_string(&err).unwrap().as_str())
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
console::warn_1(&"WebSocket is not open, cannot send error. Run with dioxus serve --hot-reload to enable hot reloading.".into());
|
||||||
|
panic!("{}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for s in crate::cache::BUILTIN_INTERNED_STRINGS {
|
||||||
|
wasm_bindgen::intern(s);
|
||||||
|
}
|
||||||
|
for s in &cfg.cached_strings {
|
||||||
|
wasm_bindgen::intern(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tasks = dom.get_scheduler_channel();
|
||||||
|
|
||||||
|
let sender_callback: Rc<dyn Fn(SchedulerMsg)> =
|
||||||
|
Rc::new(move |event| tasks.unbounded_send(event).unwrap());
|
||||||
|
|
||||||
|
let should_hydrate = cfg.hydrate;
|
||||||
|
|
||||||
|
let mut websys_dom = dom::WebsysDom::new(cfg, sender_callback);
|
||||||
|
|
||||||
|
log::trace!("rebuilding app");
|
||||||
|
|
||||||
|
if should_hydrate {
|
||||||
|
// todo: we need to split rebuild and initialize into two phases
|
||||||
|
// it's a waste to produce edits just to get the vdom loaded
|
||||||
|
let _ = dom.rebuild();
|
||||||
|
|
||||||
|
if let Err(err) = websys_dom.rehydrate(&dom) {
|
||||||
|
log::error!(
|
||||||
|
"Rehydration failed {:?}. Rebuild DOM into element from scratch",
|
||||||
|
&err
|
||||||
|
);
|
||||||
|
|
||||||
|
websys_dom.root.set_text_content(None);
|
||||||
|
|
||||||
|
// errrrr we should split rebuild into two phases
|
||||||
|
// one that initializes things and one that produces edits
|
||||||
|
let edits = dom.rebuild();
|
||||||
|
|
||||||
|
websys_dom.apply_edits(edits.edits);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let edits = dom.rebuild();
|
||||||
|
websys_dom.apply_edits(edits.edits);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut work_loop = ric_raf::RafLoop::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
log::trace!("waiting for work");
|
log::trace!("waiting for work");
|
||||||
// if virtualdom has nothing, wait for it to have something before requesting idle time
|
// if virtualdom has nothing, wait for it to have something before requesting idle time
|
||||||
|
|||||||
Reference in new issue
Block a user