From c4f98689a1902f46384ac6824d987715591112c1 Mon Sep 17 00:00:00 2001 From: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Date: Mon, 16 Feb 2026 09:44:58 +0100 Subject: [PATCH] Revert "gpui: Defer thermal/keyboard state updates when app is borrowed" (#49251) Reverts #49189 Reverts #49187 #49189 introduces a panic (https://github.com/zed-industries/zed/pull/49189#issuecomment-3904914597, https://github.com/zed-industries/zed/issues/49181#issuecomment-3906639392) #49187 It's wrong since it leads to missing updates The original crash should be fixed with #49086 cc: @bennetbo Release Notes: - N/A --- crates/gpui/.rules | 9 --------- crates/gpui/src/app.rs | 31 ++++++++++--------------------- 2 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 crates/gpui/.rules diff --git a/crates/gpui/.rules b/crates/gpui/.rules deleted file mode 100644 index 2f8b309cddc5480598be470996df5dd14b61d0c0..0000000000000000000000000000000000000000 --- a/crates/gpui/.rules +++ /dev/null @@ -1,9 +0,0 @@ -# GPUI crate-specific rules -# -# This file is non-exhaustive. Check the root .rules for general guidelines. - -# Platform callbacks - -* Platform callbacks (e.g., `on_keyboard_layout_change`, `on_thermal_state_change`) can fire - asynchronously from macOS while `AppCell` is already borrowed. Defer work via - `ForegroundExecutor::spawn` rather than borrowing `AppCell` directly in the callback body. diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index df66e74f9f19d04dfce2eb299155f57a1d832dba..4c7c68942ed9d4d2e2df0971b0f541269afae7e8 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -654,7 +654,6 @@ impl App { ) -> Rc { let background_executor = platform.background_executor(); let foreground_executor = platform.foreground_executor(); - let callback_executor = foreground_executor.clone(); assert!( background_executor.is_main_thread(), "must construct App on main thread" @@ -731,36 +730,26 @@ impl App { platform.on_keyboard_layout_change(Box::new({ let app = Rc::downgrade(&app); - let executor = callback_executor.clone(); move || { if let Some(app) = app.upgrade() { - executor - .spawn(async move { - let mut cx = app.borrow_mut(); - cx.keyboard_layout = cx.platform.keyboard_layout(); - cx.keyboard_mapper = cx.platform.keyboard_mapper(); - cx.keyboard_layout_observers - .clone() - .retain(&(), move |callback| (callback)(&mut cx)); - }) - .detach(); + let cx = &mut app.borrow_mut(); + cx.keyboard_layout = cx.platform.keyboard_layout(); + cx.keyboard_mapper = cx.platform.keyboard_mapper(); + cx.keyboard_layout_observers + .clone() + .retain(&(), move |callback| (callback)(cx)); } } })); platform.on_thermal_state_change(Box::new({ let app = Rc::downgrade(&app); - let executor = callback_executor; move || { if let Some(app) = app.upgrade() { - executor - .spawn(async move { - let mut cx = app.borrow_mut(); - cx.thermal_state_observers - .clone() - .retain(&(), move |callback| (callback)(&mut cx)); - }) - .detach(); + let cx = &mut app.borrow_mut(); + cx.thermal_state_observers + .clone() + .retain(&(), move |callback| (callback)(cx)); } } }));