diff --git a/leptos/Cargo.toml b/leptos/Cargo.toml index d9b462814..ab4c373b3 100644 --- a/leptos/Cargo.toml +++ b/leptos/Cargo.toml @@ -56,6 +56,7 @@ hydration = [ "reactive_graph/hydration", "leptos_server/hydration", "hydration_context/browser", + "leptos_dom/hydration" ] csr = ["leptos_macro/csr", "reactive_graph/effects"] hydrate = [ diff --git a/leptos_dom/Cargo.toml b/leptos_dom/Cargo.toml index 4b862b8dd..8ed712f41 100644 --- a/leptos_dom/Cargo.toml +++ b/leptos_dom/Cargo.toml @@ -30,6 +30,7 @@ features = ["Location"] default = [] tracing = ["dep:tracing"] trace-component-props = ["dep:serde", "dep:serde_json"] +hydration = ["reactive_graph/hydration"] [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] diff --git a/leptos_dom/src/helpers.rs b/leptos_dom/src/helpers.rs index 8936d95a2..c84d3d3b7 100644 --- a/leptos_dom/src/helpers.rs +++ b/leptos_dom/src/helpers.rs @@ -64,18 +64,17 @@ pub fn location() -> web_sys::Location { /// Current [`window.location.hash`](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) /// without the beginning #. pub fn location_hash() -> Option { - // TODO use shared context for is_server - /*if is_server() { + if is_server() { None - } else {*/ - location() - .hash() - .ok() - .map(|hash| match hash.chars().next() { - Some('#') => hash[1..].to_string(), - _ => hash, - }) - //} + } else { + location() + .hash() + .ok() + .map(|hash| match hash.chars().next() { + Some('#') => hash[1..].to_string(), + _ => hash, + }) + } } /// Current [`window.location.pathname`](https://developer.mozilla.org/en-US/docs/Web/API/Window/location). @@ -475,9 +474,7 @@ pub fn window_event_listener_untyped( cb(e); }; - // TODO use shared context for is_server - if true { - // !is_server() { + if !is_server() { #[inline(never)] fn wel( cb: Box, @@ -550,3 +547,16 @@ impl WindowListenerHandle { (self.0)() } } + +fn is_server() -> bool { + #[cfg(feature = "hydration")] + { + Owner::current_shared_context() + .map(|sc| !sc.is_browser()) + .unwrap_or(false) + } + #[cfg(not(feature = "hydration"))] + { + false + } +}