Skip to content

Commit

Permalink
fix: broken Suspense when a resource loads immediately (closes #1805)…
Browse files Browse the repository at this point in the history
… (#1809)
  • Loading branch information
gbj authored Sep 29, 2023
1 parent 2d63436 commit 7378b85
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions leptos_reactive/src/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7378b85

Please sign in to comment.