mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 13:24:05 -05:00
Compare commits
8 Commits
v0.8.11
...
csr-hydrat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3665c5227e | ||
|
|
653432f827 | ||
|
|
05a863edb7 | ||
|
|
ab28d26bba | ||
|
|
da3ae03422 | ||
|
|
89140b0c8d | ||
|
|
3fb34710e5 | ||
|
|
866212c2ae |
@@ -152,6 +152,7 @@ pub use leptos_config::{self, get_configuration, LeptosOptions};
|
||||
any(feature = "csr", feature = "hydrate")
|
||||
)))]
|
||||
/// Utilities for server-side rendering HTML.
|
||||
#[cfg(any(doc, not(feature = "csr")))]
|
||||
pub mod ssr {
|
||||
pub use leptos_dom::{ssr::*, ssr_in_order::*};
|
||||
}
|
||||
|
||||
@@ -76,7 +76,10 @@ where
|
||||
let current_id = current_id;
|
||||
|
||||
let children = Rc::new(orig_children(cx).into_view(cx));
|
||||
#[cfg(not(any(feature = "csr", feature = "hydrate")))]
|
||||
#[cfg(all(
|
||||
feature = "ssr",
|
||||
not(any(feature = "csr", feature = "hydrate"))
|
||||
))]
|
||||
let orig_children = Rc::clone(&orig_children);
|
||||
move || {
|
||||
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
||||
@@ -108,6 +111,7 @@ where
|
||||
else {
|
||||
HydrationCtx::continue_from(current_id);
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
cx.register_suspense(
|
||||
context,
|
||||
¤t_id.to_string(),
|
||||
|
||||
@@ -21,7 +21,9 @@ pub mod math;
|
||||
mod node_ref;
|
||||
/// Utilities for exporting nonces to be used for a Content Security Policy.
|
||||
pub mod nonce;
|
||||
#[cfg(not(feature = "csr"))]
|
||||
pub mod ssr;
|
||||
#[cfg(not(feature = "csr"))]
|
||||
pub mod ssr_in_order;
|
||||
pub mod svg;
|
||||
mod transparent;
|
||||
|
||||
@@ -234,6 +234,7 @@ impl View {
|
||||
self.into_stream_chunks_helper(cx, &mut chunks, false);
|
||||
chunks
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
fn into_stream_chunks_helper(
|
||||
self,
|
||||
|
||||
@@ -80,6 +80,7 @@ mod context;
|
||||
#[macro_use]
|
||||
mod diagnostics;
|
||||
mod effect;
|
||||
#[cfg(not(feature = "csr"))]
|
||||
mod hydration;
|
||||
mod memo;
|
||||
mod node;
|
||||
@@ -101,6 +102,7 @@ mod watch;
|
||||
pub use context::*;
|
||||
pub use diagnostics::SpecialNonReactiveZone;
|
||||
pub use effect::*;
|
||||
#[cfg(not(feature = "csr"))]
|
||||
pub use hydration::FragmentData;
|
||||
pub use memo::*;
|
||||
pub use resource::*;
|
||||
|
||||
@@ -378,7 +378,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "hydrate"))]
|
||||
#[cfg(not(all(feature = "hydrate", not(feature = "csr"))))]
|
||||
fn load_resource<S, T>(_cx: Scope, _id: ResourceId, r: Rc<ResourceState<S, T>>)
|
||||
where
|
||||
S: PartialEq + Clone + 'static,
|
||||
@@ -391,7 +391,7 @@ where
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "hydrate")]
|
||||
#[cfg(all(feature = "hydrate", not(feature = "csr")))]
|
||||
fn load_resource<S, T>(cx: Scope, id: ResourceId, r: Rc<ResourceState<S, T>>)
|
||||
where
|
||||
S: PartialEq + Clone + 'static,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
#[cfg(not(feature = "csr"))]
|
||||
use crate::hydration::SharedContext;
|
||||
use crate::{
|
||||
hydration::SharedContext,
|
||||
node::{NodeId, ReactiveNode, ReactiveNodeState, ReactiveNodeType},
|
||||
AnyComputation, AnyResource, Effect, Memo, MemoState, ReadSignal,
|
||||
ResourceId, ResourceState, RwSignal, Scope, ScopeDisposer, ScopeId,
|
||||
@@ -44,6 +45,7 @@ type FxIndexSet<T> = IndexSet<T, BuildHasherDefault<FxHasher>>;
|
||||
// and other data included in the reactive system.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Runtime {
|
||||
#[cfg(not(feature = "csr"))]
|
||||
pub shared_context: RefCell<SharedContext>,
|
||||
pub observer: Cell<Option<NodeId>>,
|
||||
pub scopes: RefCell<SlotMap<ScopeId, RefCell<Vec<ScopeProperty>>>>,
|
||||
@@ -350,9 +352,12 @@ impl Runtime {
|
||||
|
||||
impl Debug for Runtime {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Runtime")
|
||||
.field("shared_context", &self.shared_context)
|
||||
.field("observer", &self.observer)
|
||||
let mut s = f.debug_struct("Runtime");
|
||||
|
||||
#[cfg(not(feature = "csr"))]
|
||||
s.field("shared_context", &self.shared_context);
|
||||
|
||||
s.field("observer", &self.observer)
|
||||
.field("scopes", &self.scopes)
|
||||
.field("scope_parents", &self.scope_parents)
|
||||
.field("scope_children", &self.scope_children)
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#![forbid(unsafe_code)]
|
||||
use crate::{
|
||||
console_warn,
|
||||
hydration::FragmentData,
|
||||
node::NodeId,
|
||||
runtime::{with_runtime, RuntimeId},
|
||||
suspense::StreamChunk,
|
||||
PinnedFuture, ResourceId, StoredValueId, SuspenseContext,
|
||||
PinnedFuture, ResourceId, StoredValueId,
|
||||
};
|
||||
#[cfg(not(feature = "csr"))]
|
||||
use crate::{hydration::FragmentData, suspense::StreamChunk, SuspenseContext};
|
||||
use futures::stream::FuturesUnordered;
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
fmt,
|
||||
};
|
||||
#[cfg(not(feature = "csr"))]
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::fmt;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[must_use = "Scope will leak memory if the disposer function is never called"]
|
||||
@@ -459,6 +458,7 @@ impl Scope {
|
||||
|
||||
/// Registers the given [`SuspenseContext`](crate::SuspenseContext) with the current scope,
|
||||
/// calling the `resolver` when its resources are all resolved.
|
||||
#[cfg(not(feature = "csr"))]
|
||||
#[cfg_attr(
|
||||
any(debug_assertions, feature = "ssr"),
|
||||
instrument(level = "trace", skip_all,)
|
||||
@@ -516,6 +516,7 @@ impl Scope {
|
||||
///
|
||||
/// The keys are hydration IDs. Values are tuples of two pinned
|
||||
/// `Future`s that return content for out-of-order and in-order streaming, respectively.
|
||||
#[cfg(not(feature = "csr"))]
|
||||
#[cfg_attr(
|
||||
any(debug_assertions, feature = "ssr"),
|
||||
instrument(level = "trace", skip_all,)
|
||||
@@ -529,6 +530,7 @@ impl Scope {
|
||||
}
|
||||
|
||||
/// A future that will resolve when all blocking fragments are ready.
|
||||
#[cfg(not(feature = "csr"))]
|
||||
#[cfg_attr(
|
||||
any(debug_assertions, feature = "ssr"),
|
||||
instrument(level = "trace", skip_all,)
|
||||
@@ -556,6 +558,7 @@ impl Scope {
|
||||
///
|
||||
/// Returns a tuple of two pinned `Future`s that return content for out-of-order
|
||||
/// and in-order streaming, respectively.
|
||||
#[cfg(not(feature = "csr"))]
|
||||
#[cfg_attr(
|
||||
any(debug_assertions, feature = "ssr"),
|
||||
instrument(level = "trace", skip_all,)
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use cfg_if::cfg_if;
|
||||
use leptos::*;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
/// Contains the current metadata for the document's `<body>`.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct BodyContext {
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
class: Rc<RefCell<Option<TextProp>>>,
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
attributes: Rc<RefCell<Option<MaybeSignal<AdditionalAttributes>>>>,
|
||||
}
|
||||
|
||||
impl BodyContext {
|
||||
/// Converts the `<body>` metadata into an HTML string.
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(all(any(feature = "ssr", doc), not(feature = "csr")))]
|
||||
pub fn as_string(&self) -> Option<String> {
|
||||
let class = self.class.borrow().as_ref().map(|val| {
|
||||
format!(
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
use cfg_if::cfg_if;
|
||||
use leptos::*;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
/// Contains the current metadata for the document's `<html>`.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct HtmlContext {
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
lang: Rc<RefCell<Option<TextProp>>>,
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
dir: Rc<RefCell<Option<TextProp>>>,
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
class: Rc<RefCell<Option<TextProp>>>,
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(feature = "ssr", not(feature = "csr")))]
|
||||
attributes: Rc<RefCell<Option<MaybeSignal<AdditionalAttributes>>>>,
|
||||
}
|
||||
|
||||
impl HtmlContext {
|
||||
/// Converts the `<html>` metadata into an HTML string.
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(all(any(feature = "ssr", doc), not(feature = "csr")))]
|
||||
pub fn as_string(&self) -> Option<String> {
|
||||
let lang = self.lang.borrow().as_ref().map(|val| {
|
||||
format!(
|
||||
@@ -151,7 +151,7 @@ pub fn Html(
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if #[cfg(feature = "ssr")] {
|
||||
} else if #[cfg(all(feature = "ssr", not(feature = "csr")))] {
|
||||
let meta = crate::use_head(cx);
|
||||
*meta.html.lang.borrow_mut() = lang;
|
||||
*meta.html.dir.borrow_mut() = dir;
|
||||
|
||||
@@ -115,7 +115,7 @@ impl std::fmt::Debug for MetaTagsContext {
|
||||
|
||||
impl MetaTagsContext {
|
||||
/// Converts metadata tags into an HTML string.
|
||||
#[cfg(any(feature = "ssr", docs))]
|
||||
#[cfg(all(any(feature = "ssr", doc), not(feature = "csr")))]
|
||||
pub fn as_string(&self) -> String {
|
||||
self.els
|
||||
.borrow()
|
||||
@@ -231,7 +231,7 @@ impl MetaContext {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(any(doc, feature = "ssr"), not(feature = "csr")))]
|
||||
/// Converts the existing metadata tags into HTML that can be injected into the document head.
|
||||
///
|
||||
/// This should be called *after* the app’s component tree has been rendered into HTML, so that
|
||||
@@ -284,7 +284,7 @@ impl MetaContext {
|
||||
/// Extracts the metadata that should be used to close the `<head>` tag
|
||||
/// and open the `<body>` tag. This is a helper function used in implementing
|
||||
/// server-side HTML rendering across crates.
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(any(doc, feature = "ssr"), not(feature = "csr")))]
|
||||
pub fn generate_head_metadata(cx: Scope) -> String {
|
||||
let (head, body) = generate_head_metadata_separated(cx);
|
||||
format!("{head}</head><{body}>")
|
||||
@@ -293,7 +293,7 @@ pub fn generate_head_metadata(cx: Scope) -> String {
|
||||
/// Extracts the metadata that should be inserted at the beginning of the `<head>` tag
|
||||
/// and on the opening `<body>` tag. This is a helper function used in implementing
|
||||
/// server-side HTML rendering across crates.
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(all(any(doc, feature = "ssr"), not(feature = "csr")))]
|
||||
pub fn generate_head_metadata_separated(cx: Scope) -> (String, String) {
|
||||
let meta = use_context::<MetaContext>(cx);
|
||||
let head = meta
|
||||
|
||||
Reference in New Issue
Block a user