From b9c705c72eddb6b457569be950fca691ed2d48ba Mon Sep 17 00:00:00 2001 From: feeiyu <158308373+feeiyu@users.noreply.github.com> Date: Mon, 10 Nov 2025 22:52:03 +0800 Subject: [PATCH] Fix circular reference issue between EditPredictionButton and PopoverMenuHandle (#42351) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #ISSUE While working on issue #40906, I discovered that RemoteClient was not being released after the remote project closed. Analysis revealed a circular reference between EditPredictionButton and PopoverMenuHandle. Dependency Chain: RemoteClient → Project → ZetaEditPredictionProvider → EditPredictionButton ↔ PopoverMenuHandle image a) EditPredictionButton hold the reference of PopoverMenuHandle https://github.com/zed-industries/zed/blob/dc16897144700e4f949347e4ba7b8ef05c0b8efc/crates/zed/src/zed.rs#L386-L394 b) PopoverMenuHandle hold the reference of Fn which capture `Entity` https://github.com/zed-industries/zed/blob/be5a67cbdac5c503aa2626d757c82f07484eeac4/crates/edit_prediction_button/src/edit_prediction_button.rs#L382-L389 https://github.com/zed-industries/zed/blob/edaf9e122cbd198eacfdb0041ddb6fdff438e620/crates/ui/src/components/popover_menu.rs#L376-L384 Release Notes: - N/A --- crates/edit_prediction_button/src/edit_prediction_button.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/edit_prediction_button/src/edit_prediction_button.rs b/crates/edit_prediction_button/src/edit_prediction_button.rs index 70c861ab11..6e9000bc62 100644 --- a/crates/edit_prediction_button/src/edit_prediction_button.rs +++ b/crates/edit_prediction_button/src/edit_prediction_button.rs @@ -379,11 +379,12 @@ impl Render for EditPredictionButton { }) }); - let this = cx.entity(); + let this = cx.weak_entity(); let mut popover_menu = PopoverMenu::new("zeta") .menu(move |window, cx| { - Some(this.update(cx, |this, cx| this.build_zeta_context_menu(window, cx))) + this.update(cx, |this, cx| this.build_zeta_context_menu(window, cx)) + .ok() }) .anchor(Corner::BottomRight) .with_handle(self.popover_menu_handle.clone());