fix: use ready nodes in more places

This commit is contained in:
Jonathan Kelley committed 2022-12-25 01:37:00 -05:00
1 parent 85f6ea0545
commit 9b0244ee5c
10 files changed
+20 -20

No files matched your search

+8 -11
View File
@@ -43,7 +43,7 @@ impl<'b> VirtualDom {
(Aborted(l), Aborted(r)) => r.id.set(l.id.get()), (Aborted(l), Aborted(r)) => r.id.set(l.id.get()),
// Becomes async, do nothing while we ait // Becomes async, do nothing while we ait
(Ready(nodes), Async(fut)) => todo!(), (Ready(_nodes), Async(_fut)) => self.diff_ok_to_async(_nodes, scope),
// Placeholder becomes something // Placeholder becomes something
// We should also clear the error now // We should also clear the error now
@@ -61,12 +61,12 @@ impl<'b> VirtualDom {
self.scope_stack.pop(); self.scope_stack.pop();
} }
fn diff_ok_to_err(&mut self, _l: &'b VNode<'b>, _p: &'b VPlaceholder) { fn diff_ok_to_async(&mut self, _new: &'b VNode<'b>, _scope: ScopeId) {
todo!() //
} }
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!("Dioxus cannot currently recover a component after it has been errored. It must be removed from a parent"); todo!()
} }
fn diff_node(&mut self, left_template: &'b VNode<'b>, right_template: &'b VNode<'b>) { fn diff_node(&mut self, left_template: &'b VNode<'b>, right_template: &'b VNode<'b>) {
@@ -699,7 +699,7 @@ impl<'b> VirtualDom {
let scope = comp.scope.get().unwrap(); let scope = comp.scope.get().unwrap();
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } { match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
RenderReturn::Ready(node) => self.push_all_real_nodes(node), RenderReturn::Ready(node) => self.push_all_real_nodes(node),
RenderReturn::Aborted(node) => todo!(), RenderReturn::Aborted(_node) => todo!(),
_ => todo!(), _ => todo!(),
} }
} }
@@ -803,7 +803,7 @@ impl<'b> VirtualDom {
} }
fn reclaim_roots(&mut self, node: &VNode, gen_muts: bool) { fn reclaim_roots(&mut self, node: &VNode, gen_muts: bool) {
for (idx, _) in node.template.roots.iter().enumerate() { for idx in 0..node.template.roots.len() {
if let Some(dy) = node.dynamic_root(idx) { if let Some(dy) = node.dynamic_root(idx) {
self.remove_dynamic_node(dy, gen_muts); self.remove_dynamic_node(dy, gen_muts);
} else { } else {
@@ -883,10 +883,7 @@ impl<'b> VirtualDom {
.expect("VComponents to always have a scope"); .expect("VComponents to always have a scope");
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } { match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
RenderReturn::Ready(t) => { RenderReturn::Ready(t) => self.remove_node(t, gen_muts),
println!("Removing component node sync {:?}", gen_muts);
self.remove_node(t, gen_muts)
}
_ => todo!("cannot handle nonstandard nodes"), _ => todo!("cannot handle nonstandard nodes"),
}; };
+2 -2
View File
@@ -8,7 +8,7 @@ use std::{
/// A boundary that will capture any errors from child components /// A boundary that will capture any errors from child components
pub struct ErrorBoundary { pub struct ErrorBoundary {
error: RefCell<Option<CapturedError>>, error: RefCell<Option<CapturedError>>,
id: ScopeId, _id: ScopeId,
} }
/// An instance of an error captured by a descendant component. /// An instance of an error captured by a descendant component.
@@ -36,7 +36,7 @@ impl ErrorBoundary {
pub fn new(id: ScopeId) -> Self { pub fn new(id: ScopeId) -> Self {
Self { Self {
error: RefCell::new(None), error: RefCell::new(None),
id, _id: id,
} }
} }
-1
View File
@@ -6,7 +6,6 @@ use std::sync::Arc;
use std::{ use std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
collections::HashSet, collections::HashSet,
rc::Rc,
}; };
/// An ID representing an ongoing suspended component /// An ID representing an ongoing suspended component
+1 -1
View File
@@ -2,8 +2,8 @@ use super::{waker::ArcWake, Scheduler, SchedulerMsg};
use crate::ScopeId; use crate::ScopeId;
use std::cell::RefCell; use std::cell::RefCell;
use std::future::Future; use std::future::Future;
use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::{pin::Pin, rc::Rc};
/// A task's unique identifier. /// A task's unique identifier.
/// ///
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::{ use crate::{
any_props::AnyProps, any_props::AnyProps,
bump_frame::BumpFrame, bump_frame::BumpFrame,
innerlude::{DirtyScope, VPlaceholder}, innerlude::DirtyScope,
innerlude::{SuspenseId, SuspenseLeaf}, innerlude::{SuspenseId, SuspenseLeaf},
nodes::RenderReturn, nodes::RenderReturn,
scheduler::ArcWake, scheduler::ArcWake,
+1 -1
View File
@@ -485,7 +485,7 @@ impl VirtualDom {
}); });
} }
// If an error occurs, we should try to render the default error component and context where the error occured // If an error occurs, we should try to render the default error component and context where the error occured
RenderReturn::Aborted(placeholder) => panic!("Cannot catch errors during rebuild"), RenderReturn::Aborted(_placeholder) => panic!("Cannot catch errors during rebuild"),
RenderReturn::Async(_) => unreachable!("Root scope cannot be an async component"), RenderReturn::Async(_) => unreachable!("Root scope cannot be an async component"),
} }
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::{Error as RouterError, ParsedRoute, RouteContext, RouterContext}; use crate::{ParsedRoute, RouteContext, RouterContext};
use dioxus::core::{ScopeId, ScopeState}; use dioxus::core::{ScopeId, ScopeState};
use std::{borrow::Cow, str::FromStr, sync::Arc}; use std::{borrow::Cow, str::FromStr, sync::Arc};
use url::Url; use url::Url;
+4
View File
@@ -31,7 +31,11 @@ mod service;
pub use routecontext::*; pub use routecontext::*;
pub use service::*; pub use service::*;
/// An error specific to the Router
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
/// The route was not found while trying to navigate to it.
///
/// This will force the router to redirect to the 404 page.
NotFound, NotFound,
} }
+1 -1
View File
@@ -17,7 +17,7 @@ fn app(cx: Scope) -> Element {
width: "100%", width: "100%",
background_color: "hsl({hue}, 70%, {brightness}%)", background_color: "hsl({hue}, 70%, {brightness}%)",
onmousemove: move |evt| { onmousemove: move |evt| {
if let RenderReturn::Sync(Some(node)) = cx.root_node() { if let RenderReturn::Ready(node) = cx.root_node() {
if let Some(id) = node.root_ids[0].get() { if let Some(id) = node.root_ids[0].get() {
let node = tui_query.get(id); let node = tui_query.get(id);
let Size{width, height} = node.size().unwrap(); let Size{width, height} = node.size().unwrap();
+1 -1
View File
@@ -10,7 +10,7 @@ use dioxus_core::{ElementId, RenderReturn, Scope};
pub use input::*; pub use input::*;
pub(crate) fn get_root_id<T>(cx: Scope<T>) -> Option<ElementId> { pub(crate) fn get_root_id<T>(cx: Scope<T>) -> Option<ElementId> {
if let RenderReturn::Sync(Some(sync)) = cx.root_node() { if let RenderReturn::Ready(sync) = cx.root_node() {
sync.root_ids.get(0).and_then(|id| id.get()) sync.root_ids.get(0).and_then(|id| id.get())
} else { } else {
None None