diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs index 9ffb23943b6c9b8de7ab88cb46b3b31a37f69c8b..9a58112e0094c0c8ba2abfd7cee5db8bbe984108 100644 --- a/crates/gpui3/src/app.rs +++ b/crates/gpui3/src/app.rs @@ -146,6 +146,7 @@ impl AppContext { } fn flush_effects(&mut self) { + dbg!("flush effects"); while let Some(effect) = self.pending_effects.pop_front() { match effect { Effect::Notify(entity_id) => self.apply_notify_effect(entity_id), diff --git a/crates/gpui3/src/app/async_context.rs b/crates/gpui3/src/app/async_context.rs index 65f4e666b318fd3b44d270f352aee7f1dc3882af..026a1b0a076edc0928bd1f9396187cab56e32c84 100644 --- a/crates/gpui3/src/app/async_context.rs +++ b/crates/gpui3/src/app/async_context.rs @@ -67,6 +67,12 @@ impl AsyncWindowContext { pub fn update(&self, update: impl FnOnce(&mut WindowContext) -> R) -> Result { self.app.update_window(self.window, update) } + + pub fn on_next_frame(&mut self, f: impl FnOnce(&mut WindowContext) + Send + 'static) { + self.app + .update_window(self.window, |cx| cx.on_next_frame(f)) + .ok(); + } } impl Context for AsyncWindowContext { diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index 28bc51a04d5c12f702c5de0b4e2e0e524cf58f70..29ddcc3702d15c9d27d4c9a4352693d34501e869 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -75,12 +75,11 @@ impl Element for Img { let corner_radii = style.corner_radii.to_pixels(bounds, cx.rem_size()); cx.paint_image(bounds, corner_radii, order, data, self.grayscale)?; } else { - cx.spawn(|view, mut cx| async move { + cx.spawn(|_, mut cx| async move { if image_future.await.log_err().is_some() { - view.update(&mut cx, |_, cx| { + cx.on_next_frame(|cx| { cx.notify(); - }) - .ok(); + }); } }) .detach()