From aa9340547cba69daa43571c4ad587f71e4a7ed8c Mon Sep 17 00:00:00 2001 From: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Date: Mon, 23 Feb 2026 13:15:10 +0100 Subject: [PATCH] gpui: Read thermal state from window handle (#49847) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should close #49566 Inside `on_request_frame`, it’s conceptually incorrect to update the application directly. Instead, we should read the thermal state through the window handle, just like in the rest of the callback. That path uses `try_borrow_mut` internally, so if the application is already being updated elsewhere, we can safely skip checking the thermal state for that frame and retry on the next one. Before you mark this PR as ready for review, make sure that you have: - [ ] Added a solid test coverage and/or screenshots from doing manual testing - [x] Done a self-review taking into account security and performance aspects - [ ] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - N/A --- crates/gpui/src/window.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 92101fdfcacd36b6d71e0d422f3fd2cc6d773e3a..7301bdaa6ec2dfe78a7454482fa0aeca48f2fd90 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -1186,9 +1186,12 @@ impl Window { let next_frame_callbacks = next_frame_callbacks.clone(); let input_rate_tracker = input_rate_tracker.clone(); move |request_frame_options| { - let thermal_state = cx.update(|cx| cx.thermal_state()); + let thermal_state = handle + .update(&mut cx, |_, _, cx| cx.thermal_state()) + .log_err(); - if thermal_state == ThermalState::Serious || thermal_state == ThermalState::Critical + if thermal_state == Some(ThermalState::Serious) + || thermal_state == Some(ThermalState::Critical) { let now = Instant::now(); let last_frame_time = last_frame_time.replace(Some(now));