From 0fd7799bc202be3227c2df871a48b2e1bbeffb33 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 2 Feb 2024 13:36:19 -0800 Subject: [PATCH] disable use_future on the server --- packages/core/src/virtual_dom.rs | 2 ++ packages/hooks/src/use_future.rs | 1 + packages/signals/src/rc.rs | 5 ++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index b22ff7860..011e21944 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -448,6 +448,8 @@ impl VirtualDom { // Hold a lock to the flush sync to prevent tasks from running in the event we get an immediate // When we're doing awaiting the rx, the lock will be dropped and tasks waiting on the lock will get waked + // We have to own the lock since poll_tasks is cancel safe - the future that this is running in might get dropped + // and if we held the lock in the scope, the lock would also get dropped prematurely self.runtime.acquire_flush_lock(); match self.rx.next().await.expect("channel should never close") { diff --git a/packages/hooks/src/use_future.rs b/packages/hooks/src/use_future.rs index a30766500..c9596d295 100644 --- a/packages/hooks/src/use_future.rs +++ b/packages/hooks/src/use_future.rs @@ -21,6 +21,7 @@ where let mut callback = use_callback(move || { let fut = future(); spawn(async move { + flush_sync().await; state.set(UseFutureState::Pending); fut.await; state.set(UseFutureState::Complete); diff --git a/packages/signals/src/rc.rs b/packages/signals/src/rc.rs index 227c7856d..6142c5135 100644 --- a/packages/signals/src/rc.rs +++ b/packages/signals/src/rc.rs @@ -1,6 +1,5 @@ use dioxus_core::prelude::{ - consume_context, consume_context_from_scope, current_scope_id, has_context, needs_update_any, - provide_context, schedule_update, schedule_update_any, try_consume_context, ScopeId, + current_scope_id, has_context, needs_update_any, provide_context, ScopeId, }; use generational_box::{GenerationalBoxId, SyncStorage}; use rustc_hash::{FxHashMap, FxHashSet}; @@ -16,7 +15,7 @@ use crate::{CopyValue, RcList, Readable, Writable}; /// When the ReactiveContext drops, it will remove itself from the the associated contexts attached to signal #[derive(Clone, Copy, PartialEq, Eq)] pub struct ReactiveContext { - pub inner: CopyValue, + inner: CopyValue, } thread_local! {