fix rendering aborted nodes in SSR (#2218)
This commit is contained in:
1 parent
aca38e6a34
commit
947b23bda5
4 files changed
+6
-50
No files matched your search
@@ -4,9 +4,8 @@ use std::fmt::Write;
|
|||||||
use crate::renderer::{str_truthy, BOOL_ATTRS};
|
use crate::renderer::{str_truthy, BOOL_ATTRS};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StringCache {
|
pub(crate) struct StringCache {
|
||||||
pub segments: Vec<Segment>,
|
pub segments: Vec<Segment>,
|
||||||
pub template: Template,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -56,7 +55,6 @@ impl StringCache {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
segments: chain.segments,
|
segments: chain.segments,
|
||||||
template: template.template.get(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use std::{
|
use std::{path::PathBuf, time::Duration};
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
path::PathBuf,
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Information about the freshness of a rendered response
|
/// Information about the freshness of a rendered response
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@@ -60,31 +56,6 @@ impl RenderFreshness {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WriteBuffer {
|
|
||||||
buffer: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Write for WriteBuffer {
|
|
||||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
|
||||||
self.buffer.extend_from_slice(s.as_bytes());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for WriteBuffer {
|
|
||||||
type Target = Vec<u8>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.buffer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DerefMut for WriteBuffer {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.buffer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct ValidCachedPath {
|
pub(crate) struct ValidCachedPath {
|
||||||
pub(crate) full_path: PathBuf,
|
pub(crate) full_path: PathBuf,
|
||||||
pub(crate) timestamp: std::time::SystemTime,
|
pub(crate) timestamp: std::time::SystemTime,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use crate::fs_cache::ValidCachedPath;
|
|
||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use dioxus_core::VirtualDom;
|
use dioxus_core::VirtualDom;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use super::cache::Segment;
|
use super::cache::Segment;
|
||||||
use crate::cache::StringCache;
|
use crate::cache::StringCache;
|
||||||
use dioxus_core::RenderReturn;
|
|
||||||
|
|
||||||
use dioxus_core::Attribute;
|
|
||||||
use dioxus_core::{prelude::*, AttributeValue, DynamicNode};
|
use dioxus_core::{prelude::*, AttributeValue, DynamicNode};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
@@ -55,12 +53,9 @@ impl Renderer {
|
|||||||
dom: &VirtualDom,
|
dom: &VirtualDom,
|
||||||
scope: ScopeId,
|
scope: ScopeId,
|
||||||
) -> std::fmt::Result {
|
) -> std::fmt::Result {
|
||||||
// We should never ever run into async or errored nodes in SSR
|
let node = dom.get_scope(scope).unwrap().root_node();
|
||||||
// Error boundaries and suspense boundaries will convert these to sync
|
self.dynamic_node_id = 0;
|
||||||
if let RenderReturn::Ready(node) = dom.get_scope(scope).unwrap().root_node() {
|
self.render_template(buf, dom, node)?;
|
||||||
self.dynamic_node_id = 0;
|
|
||||||
self.render_template(buf, dom, node)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -122,14 +117,7 @@ impl Renderer {
|
|||||||
} else {
|
} else {
|
||||||
let scope = node.mounted_scope(*idx, template, dom).unwrap();
|
let scope = node.mounted_scope(*idx, template, dom).unwrap();
|
||||||
let node = scope.root_node();
|
let node = scope.root_node();
|
||||||
match node {
|
self.render_template(buf, dom, node)?
|
||||||
RenderReturn::Ready(node) => {
|
|
||||||
self.render_template(buf, dom, node)?
|
|
||||||
}
|
|
||||||
_ => todo!(
|
|
||||||
"generally, scopes should be sync, only if being traversed"
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DynamicNode::Text(text) => {
|
DynamicNode::Text(text) => {
|
||||||
|
|||||||
Reference in new issue
Block a user