Fix mount use after removal/Simplify mounts a bit (#2834)
* remove clone mounted; mounted nodes should never leak into components? * Remove the mount from vnodes after unmounting them * Fix use after removal in iterator diffing * remove logs * Re-fix keyed list diffing * Use new.len for diffing keyed lens and remove redundant check * simplify core list diffing logic a bit * remove println * add proper asserts for new tests --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
959ab67624
commit
d649b0c54d
13 files changed
+310
-221
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::{innerlude::CapturedPanic, nodes::RenderReturn, ComponentFunction};
|
||||
use crate::{innerlude::CapturedPanic, ComponentFunction, Element};
|
||||
use std::{any::Any, panic::AssertUnwindSafe};
|
||||
|
||||
pub(crate) type BoxedAnyProps = Box<dyn AnyProps>;
|
||||
@@ -6,7 +6,7 @@ pub(crate) type BoxedAnyProps = Box<dyn AnyProps>;
|
||||
/// A trait for a component that can be rendered.
|
||||
pub(crate) trait AnyProps: 'static {
|
||||
/// Render the component with the internal props.
|
||||
fn render(&self) -> RenderReturn;
|
||||
fn render(&self) -> Element;
|
||||
/// Make the old props equal to the new type erased props. Return if the props were equal and should be memoized.
|
||||
fn memoize(&mut self, other: &dyn Any) -> bool;
|
||||
/// Get the props as a type erased `dyn Any`.
|
||||
@@ -74,20 +74,18 @@ impl<F: ComponentFunction<P, M> + Clone, P: Clone + 'static, M: 'static> AnyProp
|
||||
&mut self.props
|
||||
}
|
||||
|
||||
fn render(&self) -> RenderReturn {
|
||||
fn render(&self) -> Element {
|
||||
let res = std::panic::catch_unwind(AssertUnwindSafe(move || {
|
||||
self.render_fn.rebuild(self.props.clone())
|
||||
}));
|
||||
|
||||
match res {
|
||||
Ok(node) => RenderReturn { node },
|
||||
Ok(node) => node,
|
||||
Err(err) => {
|
||||
let component_name = self.name;
|
||||
tracing::error!("Panic while rendering component `{component_name}`: {err:?}");
|
||||
let panic = CapturedPanic { error: err };
|
||||
RenderReturn {
|
||||
node: Err(panic.into()),
|
||||
}
|
||||
Element::Err(panic.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user