fix dioxus ssr
This commit is contained in:
1 parent
dc58212508
commit
4a1a00b0f0
27 files changed
+143
-141
No files matched your search
@@ -74,9 +74,9 @@ pub(crate) mod innerlude {
|
||||
pub use crate::innerlude::{
|
||||
fc_to_builder, generation, once, schedule_update, schedule_update_any, vdom_is_rendering,
|
||||
AnyValue, Attribute, AttributeValue, CapturedError, Component, DynamicNode, Element, ElementId,
|
||||
Event, Fragment, IntoDynNode, Mutation, MutationsVec, Properties, ScopeId, Task, Template,
|
||||
TemplateAttribute, TemplateNode, VComponent, VNode, VNodeInner, VPlaceholder, VText,
|
||||
VirtualDom, WriteMutations,
|
||||
Event, Fragment, IntoDynNode, Mutation, MutationsVec, NoOpMutations, Properties, RenderReturn,
|
||||
ScopeId, Task, Template, TemplateAttribute, TemplateNode, VComponent, VNode, VNodeInner,
|
||||
VPlaceholder, VText, VirtualDom, WriteMutations,
|
||||
};
|
||||
|
||||
/// The purpose of this module is to alleviate imports of many common types
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::any_props::{BoxedAnyProps, VProps};
|
||||
use crate::innerlude::{ElementRef, EventHandler, MountId};
|
||||
use crate::Properties;
|
||||
use crate::innerlude::{ElementRef, EventHandler, MountId, ScopeState};
|
||||
use crate::{arena::ElementId, Element, Event};
|
||||
use crate::{Properties, VirtualDom};
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::vec;
|
||||
@@ -20,7 +20,7 @@ pub type TemplateId = &'static str;
|
||||
///
|
||||
/// Dioxus will do its best to immediately resolve any async components into a regular Element, but as an implementor
|
||||
/// you might need to handle the case where there's no node immediately ready.
|
||||
pub(crate) enum RenderReturn {
|
||||
pub enum RenderReturn {
|
||||
/// A currently-available element
|
||||
Ready(VNode),
|
||||
|
||||
@@ -476,6 +476,24 @@ impl VComponent {
|
||||
props: BoxedAnyProps::new(vcomp),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the scope this node is mounted to if it's mounted
|
||||
///
|
||||
/// This is useful for rendering nodes outside of the VirtualDom, such as in SSR
|
||||
///
|
||||
/// Returns [`None`] if the node is not mounted
|
||||
pub fn mounted_scope<'a>(
|
||||
&self,
|
||||
dynamic_node_index: usize,
|
||||
vnode: &VNode,
|
||||
dom: &'a VirtualDom,
|
||||
) -> Option<&'a ScopeState> {
|
||||
let mount = vnode.mount.get().as_usize()?;
|
||||
|
||||
let scope_id = dom.mounts.get(mount)?.mounted_dynamic_nodes[dynamic_node_index];
|
||||
|
||||
dom.scopes.get(scope_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for VComponent {
|
||||
|
||||
@@ -27,10 +27,10 @@ impl ScopeId {
|
||||
pub const ROOT: ScopeId = ScopeId(0);
|
||||
}
|
||||
|
||||
/// A component's state separate from its props.
|
||||
/// A component's rendered state.
|
||||
///
|
||||
/// This struct exists to provide a common interface for all scopes without relying on generics.
|
||||
pub(crate) struct ScopeState {
|
||||
/// This state erases the type of the component's props. It is used to store the state of a component in the runtime.
|
||||
pub struct ScopeState {
|
||||
pub(crate) runtime: Rc<Runtime>,
|
||||
pub(crate) context_id: ScopeId,
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ impl VirtualDom {
|
||||
/// Get the state for any scope given its ID
|
||||
///
|
||||
/// This is useful for inserting or removing contexts from a scope, or rendering out its root node
|
||||
pub(crate) fn get_scope(&self, id: ScopeId) -> Option<&ScopeState> {
|
||||
pub fn get_scope(&self, id: ScopeId) -> Option<&ScopeState> {
|
||||
self.scopes.get(id.0)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user