From 7378b8581a166efa715fc9dab81f397b43238f64 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 29 Sep 2023 14:44:49 -0400 Subject: [PATCH] fix: broken `Suspense` when a resource loads immediately (closes #1805) (#1809) --- leptos_reactive/src/suspense.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/leptos_reactive/src/suspense.rs b/leptos_reactive/src/suspense.rs index 3f5f9e882a..8a23647f3a 100644 --- a/leptos_reactive/src/suspense.rs +++ b/leptos_reactive/src/suspense.rs @@ -118,33 +118,29 @@ impl SuspenseContext { let setter = self.set_pending_resources; let serializable_resources = self.pending_serializable_resources; let has_local_only = self.has_local_only; - queue_microtask(move || { - setter.update(|n| *n += 1); - if serializable { - serializable_resources.update(|n| *n += 1); - has_local_only.set_value(false); - } - }); + setter.update(|n| *n += 1); + if serializable { + serializable_resources.update(|n| *n += 1); + has_local_only.set_value(false); + } } /// Notifies the suspense context that a resource has resolved. pub fn decrement(&self, serializable: bool) { let setter = self.set_pending_resources; let serializable_resources = self.pending_serializable_resources; - queue_microtask(move || { - setter.update(|n| { + setter.update(|n| { + if *n > 0 { + *n -= 1 + } + }); + if serializable { + serializable_resources.update(|n| { if *n > 0 { - *n -= 1 + *n -= 1; } }); - if serializable { - serializable_resources.update(|n| { - if *n > 0 { - *n -= 1; - } - }); - } - }); + } } /// Resets the counter of pending resources.