Fix circular reference issue between EditPredictionButton and PopoverMenuHandle (#42351)

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

<img width="400" height="300" alt="image"
src="https://github.com/user-attachments/assets/6b716c9b-6938-471a-b044-397314b729d4"
/>

a) EditPredictionButton hold the reference of PopoverMenuHandle 

5f8226457e/crates/zed/src/zed.rs (L386-L394)

b) PopoverMenuHandle hold the reference of Fn which capture
`Entity<EditPredictionButton>`

5fc54986c7/crates/edit_prediction_button/src/edit_prediction_button.rs (L382-L389)


a9bc890497/crates/ui/src/components/popover_menu.rs (L376-L384)


Release Notes:

- N/A
This commit is contained in:
feeiyu
2025-11-10 22:52:03 +08:00
committed by GitHub
parent 2d84af91bf
commit 42ed032f12

View File

@@ -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());