fix: use ready nodes in more places

This commit is contained in:
Jonathan Kelley 2022-12-25 01:37:00 -05:00
parent 85f6ea0545
commit 9b0244ee5c
10 changed files with 20 additions and 20 deletions

View file

@ -43,7 +43,7 @@ impl<'b> VirtualDom {
(Aborted(l), Aborted(r)) => r.id.set(l.id.get()),
// 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
// We should also clear the error now
@ -61,12 +61,12 @@ impl<'b> VirtualDom {
self.scope_stack.pop();
}
fn diff_ok_to_err(&mut self, _l: &'b VNode<'b>, _p: &'b VPlaceholder) {
todo!()
fn diff_ok_to_async(&mut self, _new: &'b VNode<'b>, _scope: ScopeId) {
//
}
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_ok_to_err(&mut self, _l: &'b VNode<'b>, _p: &'b VPlaceholder) {
todo!()
}
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();
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
RenderReturn::Ready(node) => self.push_all_real_nodes(node),
RenderReturn::Aborted(node) => todo!(),
RenderReturn::Aborted(_node) => todo!(),
_ => todo!(),
}
}
@ -803,7 +803,7 @@ impl<'b> VirtualDom {
}
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) {
self.remove_dynamic_node(dy, gen_muts);
} else {
@ -883,10 +883,7 @@ impl<'b> VirtualDom {
.expect("VComponents to always have a scope");
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
RenderReturn::Ready(t) => {
println!("Removing component node sync {:?}", gen_muts);
self.remove_node(t, gen_muts)
}
RenderReturn::Ready(t) => self.remove_node(t, gen_muts),
_ => todo!("cannot handle nonstandard nodes"),
};

View file

@ -8,7 +8,7 @@ use std::{
/// A boundary that will capture any errors from child components
pub struct ErrorBoundary {
error: RefCell<Option<CapturedError>>,
id: ScopeId,
_id: ScopeId,
}
/// An instance of an error captured by a descendant component.
@ -36,7 +36,7 @@ impl ErrorBoundary {
pub fn new(id: ScopeId) -> Self {
Self {
error: RefCell::new(None),
id,
_id: id,
}
}

View file

@ -6,7 +6,6 @@ use std::sync::Arc;
use std::{
cell::{Cell, RefCell},
collections::HashSet,
rc::Rc,
};
/// An ID representing an ongoing suspended component

View file

@ -2,8 +2,8 @@ use super::{waker::ArcWake, Scheduler, SchedulerMsg};
use crate::ScopeId;
use std::cell::RefCell;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::{pin::Pin, rc::Rc};
/// A task's unique identifier.
///

View file

@ -1,7 +1,7 @@
use crate::{
any_props::AnyProps,
bump_frame::BumpFrame,
innerlude::{DirtyScope, VPlaceholder},
innerlude::DirtyScope,
innerlude::{SuspenseId, SuspenseLeaf},
nodes::RenderReturn,
scheduler::ArcWake,

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
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"),
}

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 std::{borrow::Cow, str::FromStr, sync::Arc};
use url::Url;

View file

@ -31,7 +31,11 @@ mod service;
pub use routecontext::*;
pub use service::*;
/// An error specific to the Router
#[derive(Debug)]
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,
}

View file

@ -17,7 +17,7 @@ fn app(cx: Scope) -> Element {
width: "100%",
background_color: "hsl({hue}, 70%, {brightness}%)",
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() {
let node = tui_query.get(id);
let Size{width, height} = node.size().unwrap();

View file

@ -10,7 +10,7 @@ use dioxus_core::{ElementId, RenderReturn, Scope};
pub use input::*;
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())
} else {
None