From 42ed032f129fbb65e1e9ddb42ac9dcf9ae71eba6 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
a) EditPredictionButton hold the reference of PopoverMenuHandle
https://github.com/zed-industries/zed/blob/5f8226457ee6e1346a224ae6b0329f014ea883f7/crates/zed/src/zed.rs#L386-L394
b) PopoverMenuHandle hold the reference of Fn which capture
`Entity`
https://github.com/zed-industries/zed/blob/5fc54986c72f2863645302c5e6a99277f8c38cab/crates/edit_prediction_button/src/edit_prediction_button.rs#L382-L389
https://github.com/zed-industries/zed/blob/a9bc890497f1edaf4f177385cf96785de60e910c/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 70c861ab1112630c2e3293cb54a4e96c6754b3bd..6e9000bc62eea94d5c48dca2416781f46428522c 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());