fix(typeahead): add defensive checks for valid Leptos owner in Bloodhound and Typeahead initialization
This commit is contained in:
parent
a9bfbf1c15
commit
dbca9a98c8
1 changed files with 22 additions and 3 deletions
|
@ -536,8 +536,19 @@ fn initialize_bloodhound(
|
||||||
let query_str = query.as_string().unwrap_or_default();
|
let query_str = query.as_string().unwrap_or_default();
|
||||||
log!("[BLOODHOUND] Fetching suggestions for: {}", query_str);
|
log!("[BLOODHOUND] Fetching suggestions for: {}", query_str);
|
||||||
|
|
||||||
|
// Defensive: check if we have a valid Leptos owner
|
||||||
|
let owner = match Owner::current() {
|
||||||
|
Some(owner) => owner,
|
||||||
|
None => {
|
||||||
|
log!("[BLOODHOUND] No Leptos owner, aborting fetch");
|
||||||
|
let empty_results = Array::new();
|
||||||
|
let _ = sync.call1(&JsValue::NULL, &empty_results);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Safely call the fetch callback
|
// Safely call the fetch callback
|
||||||
let suggestions = match try_with_owner(Owner::current().unwrap(), {
|
let suggestions = match try_with_owner(owner, {
|
||||||
// Clone these values for the inner closure
|
// Clone these values for the inner closure
|
||||||
let is_alive = is_alive.clone();
|
let is_alive = is_alive.clone();
|
||||||
let fetch = fetch.clone();
|
let fetch = fetch.clone();
|
||||||
|
@ -800,11 +811,19 @@ fn initialize_typeahead(
|
||||||
log!("[TYPEAHEAD] Component no longer alive, aborting selection handler");
|
log!("[TYPEAHEAD] Component no longer alive, aborting selection handler");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Defensive: check if we have a valid Leptos owner
|
||||||
|
let owner = match Owner::current() {
|
||||||
|
Some(owner) => owner,
|
||||||
|
None => {
|
||||||
|
log!("[TYPEAHEAD] No Leptos owner, aborting selection handler");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
log!("[TYPEAHEAD] Selection made");
|
log!("[TYPEAHEAD] Selection made");
|
||||||
|
|
||||||
// Safely call the on_select callback
|
// Safely call the on_select callback
|
||||||
let _ = try_with_owner(Owner::current().unwrap(), {
|
let _ = try_with_owner(owner, {
|
||||||
// Clone these values again for the inner closure
|
// Clone these values again for the inner closure
|
||||||
let is_alive = is_alive.clone();
|
let is_alive = is_alive.clone();
|
||||||
let on_select = on_select.clone();
|
let on_select = on_select.clone();
|
||||||
|
|
Loading…
Add table
Reference in a new issue