Skip to content

Commit d444e92

Browse files
clauderuvnet
andcommitted
Fix expect_context panics inside spawn_local async blocks
In Leptos 0.7, the reactive owner/context is not propagated into spawn_local closures. Moved expect_context::<RelayConnection>() and use_auth() calls before spawn_local in setup.rs, settings.rs, and section_requests.rs to prevent runtime panics. Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent 8fa70ba commit d444e92

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

community-forum-rs/crates/forum-client/src/admin/section_requests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ fn approve_request(req: SectionRequest, requests: RwSignal<Vec<SectionRequest>>)
286286
let cohort = req.cohort.clone();
287287
let pk = req.requester.clone();
288288

289+
let relay = expect_context::<RelayConnection>();
289290
spawn_local(async move {
290291
// Add cohort to user's whitelist entry
291292
match admin.add_to_whitelist(&pk, &[cohort.clone()], &privkey).await {
@@ -298,8 +299,7 @@ fn approve_request(req: SectionRequest, requests: RwSignal<Vec<SectionRequest>>)
298299
);
299300

300301
// Publish kind-9000 (add user to group) as confirmation
301-
let relay = expect_context::<RelayConnection>();
302-
if let Some(my_pk) = use_auth().pubkey().get_untracked() {
302+
if let Some(my_pk) = auth.pubkey().get_untracked() {
303303
let now = (js_sys::Date::now() / 1000.0) as u64;
304304
let unsigned = nostr_core::UnsignedEvent {
305305
pubkey: my_pk,
@@ -311,7 +311,6 @@ fn approve_request(req: SectionRequest, requests: RwSignal<Vec<SectionRequest>>)
311311
],
312312
content: "Approved section access request".to_string(),
313313
};
314-
let auth = use_auth();
315314
wasm_bindgen_futures::spawn_local(async move {
316315
if let Ok(signed) = auth.sign_event_async(unsigned).await {
317316
relay.publish(&signed);

community-forum-rs/crates/forum-client/src/pages/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ pub fn SettingsPage() -> impl IntoView {
206206
let toasts_ok = toasts_for_profile.clone();
207207
let toasts_pub = toasts_for_profile.clone();
208208
let toasts_err = toasts_for_profile.clone();
209+
let relay = expect_context::<RelayConnection>();
209210
wasm_bindgen_futures::spawn_local(async move {
210211
match auth.sign_event_async(unsigned).await {
211212
Ok(signed) => {
212-
let relay = expect_context::<RelayConnection>();
213213
let saving_sig = profile_saving;
214214
let auth_for_ack = auth;
215215
let name_for_ack = name.clone();

community-forum-rs/crates/forum-client/src/pages/setup.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ pub fn SetupPage() -> impl IntoView {
120120
};
121121

122122
let trimmed_for_ack = trimmed.clone();
123+
// Capture relay before spawn_local — reactive context is not
124+
// propagated into async tasks in Leptos 0.7.
125+
let relay = expect_context::<RelayConnection>();
123126
wasm_bindgen_futures::spawn_local(async move {
124127
match auth.sign_event_async(unsigned).await {
125128
Ok(signed) => {
126-
let relay = expect_context::<RelayConnection>();
127129
relay.publish(&signed);
128130

129131
auth.set_profile(Some(trimmed_for_ack), None);

0 commit comments

Comments
 (0)