diff --git a/packages/core/src/any_props.rs b/packages/core/src/any_props.rs
index c3ea4dc2c..7014a2771 100644
--- a/packages/core/src/any_props.rs
+++ b/packages/core/src/any_props.rs
@@ -1,4 +1,4 @@
-use std::marker::PhantomData;
+use std::{marker::PhantomData, panic::AssertUnwindSafe};
use crate::{
innerlude::Scoped,
@@ -62,12 +62,19 @@ where
}
fn render(&'a self, cx: &'a ScopeState) -> RenderReturn<'a> {
- let scope: &mut Scoped
= cx.bump().alloc(Scoped {
- props: &self.props,
- scope: cx,
- });
+ let res = std::panic::catch_unwind(AssertUnwindSafe(move || {
+ // Call the render function directly
+ let scope: &mut Scoped
= cx.bump().alloc(Scoped {
+ props: &self.props,
+ scope: cx,
+ });
- // Call the render function directly
- (self.render_fn)(scope).into_return(cx)
+ (self.render_fn)(scope).into_return(cx)
+ }));
+
+ match res {
+ Ok(e) => e,
+ Err(_) => RenderReturn::default(),
+ }
}
}
diff --git a/packages/core/src/arena.rs b/packages/core/src/arena.rs
index 9d723d89c..27b3a048a 100644
--- a/packages/core/src/arena.rs
+++ b/packages/core/src/arena.rs
@@ -81,12 +81,12 @@ impl VirtualDom {
self.ensure_drop_safety(id);
if let Some(root) = self.scopes[id.0].as_ref().try_root_node() {
- if let RenderReturn::Sync(Some(node)) = unsafe { root.extend_lifetime_ref() } {
+ if let RenderReturn::Ready(node) = unsafe { root.extend_lifetime_ref() } {
self.drop_scope_inner(node)
}
}
if let Some(root) = unsafe { self.scopes[id.0].as_ref().previous_frame().try_load_node() } {
- if let RenderReturn::Sync(Some(node)) = unsafe { root.extend_lifetime_ref() } {
+ if let RenderReturn::Ready(node) = unsafe { root.extend_lifetime_ref() } {
self.drop_scope_inner(node)
}
}
diff --git a/packages/core/src/create.rs b/packages/core/src/create.rs
index 239bd85fa..b2be8e60e 100644
--- a/packages/core/src/create.rs
+++ b/packages/core/src/create.rs
@@ -354,8 +354,13 @@ impl<'b> VirtualDom {
use RenderReturn::*;
match return_nodes {
- Sync(Some(t)) => self.mount_component(scope, template, t, idx),
- Sync(None) => todo!("Propogate error upwards"),
+ Ready(t) => self.mount_component(scope, template, t, idx),
+ Aborted(t) => {
+ self.mutations
+ .push(Mutation::CreatePlaceholder { id: ElementId(999) });
+
+ 1
+ }
Async(_) => self.mount_component_placeholder(template, idx, scope),
}
}
diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs
index abf938929..4112fdd55 100644
--- a/packages/core/src/diff.rs
+++ b/packages/core/src/diff.rs
@@ -30,29 +30,44 @@ impl<'b> VirtualDom {
.try_load_node()
.expect("Call rebuild before diffing");
- use RenderReturn::{Async, Sync};
+ use RenderReturn::{Aborted, Async, Ready};
match (old, new) {
- (Sync(Some(l)), Sync(Some(r))) => self.diff_node(l, r),
+ // Normal pathway
+ (Ready(l), Ready(r)) => self.diff_node(l, r),
- // Err cases
- (Sync(Some(l)), Sync(None)) => self.diff_ok_to_err(l),
- (Sync(None), Sync(Some(r))) => self.diff_err_to_ok(r),
- (Sync(None), Sync(None)) => { /* nothing */ }
+ // Unwind the mutations if need be
+ (Ready(l), Aborted(p)) => self.diff_ok_to_err(l, p),
- // Async
- (Sync(Some(_l)), Async(_)) => todo!(),
- (Sync(None), Async(_)) => todo!(),
- (Async(_), Sync(Some(_r))) => todo!(),
- (Async(_), Sync(None)) => { /* nothing */ }
- (Async(_), Async(_)) => { /* nothing */ }
+ // Just move over the placeholder
+ (Aborted(l), Aborted(r)) => r.id.set(l.id.get()),
+
+ // Becomes async, do nothing while we ait
+ (Ready(nodes), Async(fut)) => todo!(),
+
+ // Placeholder becomes something
+ // We should also clear the error now
+ (Aborted(l), Ready(r)) => self.replace_placeholder(l, [r]),
+
+ (Aborted(_), Async(_)) => todo!("async should not resolve here"),
+ (Async(_), Ready(_)) => todo!("async should not resolve here"),
+ (Async(_), Aborted(_)) => todo!("async should not resolve here"),
+ (Async(_), Async(_)) => {
+ // All suspense should resolve before we diff it again
+ panic!("Should not roll from suspense to suspense.");
+ }
};
}
self.scope_stack.pop();
}
- fn diff_ok_to_err(&mut self, _l: &'b VNode<'b>) {}
- fn diff_err_to_ok(&mut self, _l: &'b VNode<'b>) {}
+ fn diff_ok_to_err(&mut self, _l: &'b VNode<'b>, _p: &'b VPlaceholder) {
+ todo!()
+ }
+
+ fn diff_err_to_ok(&mut self, _l: &'b VNode<'b>) {
+ todo!("Dioxus cannot currently recover a component after it has been errored. It must be removed from a parent");
+ }
fn diff_node(&mut self, left_template: &'b VNode<'b>, right_template: &'b VNode<'b>) {
// If the templates are the same, we don't need to do anything, nor do we want to
@@ -118,7 +133,7 @@ impl<'b> VirtualDom {
(Fragment(left), Fragment(right)) => self.diff_non_empty_fragment(left, right),
(Placeholder(left), Placeholder(right)) => right.id.set(left.id.get()),
(Component(left), Component(right)) => self.diff_vcomponent(left, right, node, idx),
- (Placeholder(left), Fragment(right)) => self.replace_placeholder(left, right),
+ (Placeholder(left), Fragment(right)) => self.replace_placeholder(left, *right),
(Fragment(left), Placeholder(right)) => self.node_to_placeholder(left, right),
_ => todo!("This is an usual custom case for dynamic nodes. We don't know how to handle it yet."),
};
@@ -679,7 +694,8 @@ impl<'b> VirtualDom {
Component(comp) => {
let scope = comp.scope.get().unwrap();
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
- RenderReturn::Sync(Some(node)) => self.push_all_real_nodes(node),
+ RenderReturn::Ready(node) => self.push_all_real_nodes(node),
+ RenderReturn::Aborted(node) => todo!(),
_ => todo!(),
}
}
@@ -707,7 +723,11 @@ impl<'b> VirtualDom {
}
/// Simply replace a placeholder with a list of nodes
- fn replace_placeholder(&mut self, l: &'b VPlaceholder, r: &'b [VNode<'b>]) {
+ fn replace_placeholder(
+ &mut self,
+ l: &'b VPlaceholder,
+ r: impl IntoIterator- >,
+ ) {
let m = self.create_children(r);
let id = l.id.get().unwrap();
self.mutations.push(Mutation::ReplaceWith { id, m });
@@ -856,7 +876,7 @@ impl<'b> VirtualDom {
let scope = comp.scope.take().unwrap();
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
- RenderReturn::Sync(Some(t)) => {
+ RenderReturn::Ready(t) => {
println!("Removing component node sync {:?}", gen_muts);
self.remove_node(t, gen_muts)
}
@@ -886,7 +906,7 @@ impl<'b> VirtualDom {
Some(Component(comp)) => {
let scope = comp.scope.get().unwrap();
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
- RenderReturn::Sync(Some(t)) => self.find_first_element(t),
+ RenderReturn::Ready(t) => self.find_first_element(t),
_ => todo!("cannot handle nonstandard nodes"),
}
}
@@ -902,7 +922,7 @@ impl<'b> VirtualDom {
Some(Component(comp)) => {
let scope = comp.scope.get().unwrap();
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
- RenderReturn::Sync(Some(t)) => self.find_last_element(t),
+ RenderReturn::Ready(t) => self.find_last_element(t),
_ => todo!("cannot handle nonstandard nodes"),
}
}
diff --git a/packages/core/src/error_boundary.rs b/packages/core/src/error_boundary.rs
index fd8810f1a..91ac3b61d 100644
--- a/packages/core/src/error_boundary.rs
+++ b/packages/core/src/error_boundary.rs
@@ -1,14 +1,37 @@
-use std::cell::RefCell;
-
-use crate::ScopeId;
+use crate::{ScopeId, ScopeState};
+use std::{
+ any::{Any, TypeId},
+ cell::RefCell,
+ fmt::Debug,
+};
/// A boundary that will capture any errors from child components
-#[allow(dead_code)]
pub struct ErrorBoundary {
- error: RefCell