diff --git a/src/client/applications.rs b/src/client/applications.rs index 8fc67d8..906bb9c 100644 --- a/src/client/applications.rs +++ b/src/client/applications.rs @@ -22,22 +22,33 @@ fn AddApplicationModal( create_action: ServerAction, show_modal: RwSignal, ) -> impl IntoView { + use leptos::task::spawn_local; + let name_ref = NodeRef::::new(); - // Focus the name field as soon as the modal is mounted. - Effect::new(move |_| { - if let Some(el) = name_ref.get() { + // Defer focus to the next microtask so the element is in the DOM. + // Using get_untracked() avoids subscribing to NodeRef's reactive signal, + // which would otherwise re-trigger during modal unmount and cause + // "closure invoked after being dropped" in wasm-bindgen. + spawn_local(async move { + if let Some(el) = name_ref.get_untracked() { let _ = el.focus(); } }); + // close() defers show_modal.set(false) to the next microtask. + // Without this, setting the signal synchronously inside a click handler + // unmounts the modal (and frees its closures) while the handler is still + // on the call stack, causing wasm-bindgen to panic. + let close = move || spawn_local(async move { show_modal.set(false) }); + view! { -