Figuring out the right way to handle refs/event listeners in SSR mode is hard...

This commit is contained in:
Greg Johnston 2022-11-12 07:37:07 -05:00
parent 8f88b50d34
commit 19ac14cf62
2 changed files with 8 additions and 2 deletions

View file

@ -293,6 +293,9 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
/>
<label on:dblclick=move |_| {
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>() {
input.focus();
}

View file

@ -448,8 +448,11 @@ fn attr_to_tokens(
};
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
// this will cause some warnings instead about unused setters, while doing SSR
// fake the initialization; should only be used in effects or event handlers, which will never run on the server
// but if we don't initialize it, the compiler will complain
navigations.push(quote_spanned! {
span => #ident = String::new();
});
} else {
expressions.push(match &node.value {
Some(expr) => {