chore: swap over router none
This commit is contained in:
1 parent
2fa3fe1fc0
commit
5a70c6ecf9
5 files changed
+27
-9
No files matched your search
@@ -0,0 +1,11 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(app);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
button { "hello, desktop!" }
|
||||
})
|
||||
}
|
||||
@@ -136,8 +136,10 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
/// Descend through the tree, removing any borrowed props and listeners
|
||||
pub(crate) fn ensure_drop_safety(&self, scope: ScopeId) {
|
||||
let scope = &self.scopes[scope.0];
|
||||
pub(crate) fn ensure_drop_safety(&self, scope_id: ScopeId) {
|
||||
let scope = &self.scopes[scope_id.0];
|
||||
|
||||
log::debug!("Dropping props on scope {:?}", scope_id);
|
||||
|
||||
// make sure we drop all borrowed props manually to guarantee that their drop implementation is called before we
|
||||
// run the hooks (which hold an &mut Reference)
|
||||
@@ -145,10 +147,15 @@ impl VirtualDom {
|
||||
let mut props = scope.borrowed_props.borrow_mut();
|
||||
props.drain(..).for_each(|comp| {
|
||||
let comp = unsafe { &*comp };
|
||||
if let Some(scope_id) = comp.scope.get() {
|
||||
self.ensure_drop_safety(scope_id);
|
||||
match comp.scope.get() {
|
||||
Some(child) if child != scope_id => self.ensure_drop_safety(child),
|
||||
_ => (),
|
||||
}
|
||||
if let Ok(mut props) = comp.props.try_borrow_mut() {
|
||||
*props = None;
|
||||
} else {
|
||||
log::debug!("cannot drop props for comp {:?}", scope_id);
|
||||
}
|
||||
drop(comp.props.take());
|
||||
});
|
||||
|
||||
// Now that all the references are gone, we can safely drop our own references in our listeners.
|
||||
|
||||
@@ -47,5 +47,5 @@ pub fn Redirect<'a>(cx: Scope<'a, RedirectProps<'a>>) -> Element {
|
||||
router.replace_route(cx.props.to, None, None);
|
||||
}
|
||||
|
||||
None
|
||||
cx.render(rsx!(()))
|
||||
}
|
||||
@@ -52,6 +52,6 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
|
||||
cx.render(rsx!(&cx.props.children))
|
||||
} else {
|
||||
log::debug!("Route should *not* render: {:?}", cx.scope_id());
|
||||
None
|
||||
cx.render(rsx!(()))
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl Renderer {
|
||||
) -> std::fmt::Result {
|
||||
// We should never ever run into async or errored nodes in SSR
|
||||
// Error boundaries and suspense boundaries will convert these to sync
|
||||
if let RenderReturn::Sync(Some(node)) = dom.get_scope(scope).unwrap().root_node() {
|
||||
if let RenderReturn::Ready(node) = dom.get_scope(scope).unwrap().root_node() {
|
||||
self.render_template(buf, dom, node)?
|
||||
};
|
||||
|
||||
@@ -89,7 +89,7 @@ impl Renderer {
|
||||
let scope = dom.get_scope(id).unwrap();
|
||||
let node = scope.root_node();
|
||||
match node {
|
||||
RenderReturn::Sync(Some(node)) => {
|
||||
RenderReturn::Ready(node) => {
|
||||
self.render_template(buf, dom, node)?
|
||||
}
|
||||
_ => todo!(
|
||||
|
||||
Reference in new issue
Block a user