mirror of
https://github.com/leptos-rs/leptos
synced 2024-09-20 06:21:57 +00:00
This commit is contained in:
parent
998165148b
commit
2b8e987cb8
3 changed files with 26 additions and 14 deletions
|
@ -56,6 +56,7 @@ hydration = [
|
||||||
"reactive_graph/hydration",
|
"reactive_graph/hydration",
|
||||||
"leptos_server/hydration",
|
"leptos_server/hydration",
|
||||||
"hydration_context/browser",
|
"hydration_context/browser",
|
||||||
|
"leptos_dom/hydration"
|
||||||
]
|
]
|
||||||
csr = ["leptos_macro/csr", "reactive_graph/effects"]
|
csr = ["leptos_macro/csr", "reactive_graph/effects"]
|
||||||
hydrate = [
|
hydrate = [
|
||||||
|
|
|
@ -30,6 +30,7 @@ features = ["Location"]
|
||||||
default = []
|
default = []
|
||||||
tracing = ["dep:tracing"]
|
tracing = ["dep:tracing"]
|
||||||
trace-component-props = ["dep:serde", "dep:serde_json"]
|
trace-component-props = ["dep:serde", "dep:serde_json"]
|
||||||
|
hydration = ["reactive_graph/hydration"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--generate-link-to-definition"]
|
rustdoc-args = ["--generate-link-to-definition"]
|
||||||
|
|
|
@ -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)
|
/// Current [`window.location.hash`](https://developer.mozilla.org/en-US/docs/Web/API/Window/location)
|
||||||
/// without the beginning #.
|
/// without the beginning #.
|
||||||
pub fn location_hash() -> Option<String> {
|
pub fn location_hash() -> Option<String> {
|
||||||
// TODO use shared context for is_server
|
if is_server() {
|
||||||
/*if is_server() {
|
|
||||||
None
|
None
|
||||||
} else {*/
|
} else {
|
||||||
location()
|
location()
|
||||||
.hash()
|
.hash()
|
||||||
.ok()
|
.ok()
|
||||||
.map(|hash| match hash.chars().next() {
|
.map(|hash| match hash.chars().next() {
|
||||||
Some('#') => hash[1..].to_string(),
|
Some('#') => hash[1..].to_string(),
|
||||||
_ => hash,
|
_ => hash,
|
||||||
})
|
})
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current [`window.location.pathname`](https://developer.mozilla.org/en-US/docs/Web/API/Window/location).
|
/// 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);
|
cb(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO use shared context for is_server
|
if !is_server() {
|
||||||
if true {
|
|
||||||
// !is_server() {
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn wel(
|
fn wel(
|
||||||
cb: Box<dyn FnMut(web_sys::Event)>,
|
cb: Box<dyn FnMut(web_sys::Event)>,
|
||||||
|
@ -550,3 +547,16 @@ impl WindowListenerHandle {
|
||||||
(self.0)()
|
(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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue