mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
Figuring out the right way to handle refs/event listeners in SSR mode is hard...
This commit is contained in:
parent
8f88b50d34
commit
19ac14cf62
2 changed files with 8 additions and 2 deletions
|
@ -293,6 +293,9 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
|
||||||
/>
|
/>
|
||||||
<label on:dblclick=move |_| {
|
<label on:dblclick=move |_| {
|
||||||
set_editing(true);
|
set_editing(true);
|
||||||
|
|
||||||
|
// guard against the fact that in SSR mode, that ref is actually to a String
|
||||||
|
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
||||||
if let Some(input) = input.dyn_ref::<HtmlInputElement>() {
|
if let Some(input) = input.dyn_ref::<HtmlInputElement>() {
|
||||||
input.focus();
|
input.focus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,8 +448,11 @@ fn attr_to_tokens(
|
||||||
};
|
};
|
||||||
|
|
||||||
if mode == Mode::Ssr {
|
if mode == Mode::Ssr {
|
||||||
// used to fake the initialization; but if we do this, we can't do normal things like .dyn_ref() on an Element
|
// fake the initialization; should only be used in effects or event handlers, which will never run on the server
|
||||||
// this will cause some warnings instead about unused setters, while doing SSR
|
// but if we don't initialize it, the compiler will complain
|
||||||
|
navigations.push(quote_spanned! {
|
||||||
|
span => #ident = String::new();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
expressions.push(match &node.value {
|
expressions.push(match &node.value {
|
||||||
Some(expr) => {
|
Some(expr) => {
|
||||||
|
|
Loading…
Reference in a new issue