Fix panic due to re-entrantly reading `Workspace`

Antonio Scandurra created

Change summary

crates/collab_ui/src/collab_titlebar_item.rs | 7 +++++--
crates/zed/src/zed.rs                        | 4 +++-
2 files changed, 8 insertions(+), 3 deletions(-)

Detailed changes

crates/collab_ui/src/collab_titlebar_item.rs 🔗

@@ -134,9 +134,12 @@ impl View for CollabTitlebarItem {
 }
 
 impl CollabTitlebarItem {
-    pub fn new(workspace: &ViewHandle<Workspace>, cx: &mut ViewContext<Self>) -> Self {
+    pub fn new(
+        workspace: &ViewHandle<Workspace>,
+        user_store: ModelHandle<UserStore>,
+        cx: &mut ViewContext<Self>,
+    ) -> Self {
         let active_call = ActiveCall::global(cx);
-        let user_store = workspace.read(cx).user_store().clone();
         let mut subscriptions = Vec::new();
         subscriptions.push(cx.observe(workspace, |_, _, cx| cx.notify()));
         subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));

crates/zed/src/zed.rs 🔗

@@ -302,7 +302,9 @@ pub fn initialize_workspace(
     cx.emit(workspace::Event::PaneAdded(workspace.active_pane().clone()));
     cx.emit(workspace::Event::PaneAdded(workspace.dock_pane().clone()));
 
-    let collab_titlebar_item = cx.add_view(|cx| CollabTitlebarItem::new(&workspace_handle, cx));
+    let collab_titlebar_item = cx.add_view(|cx| {
+        CollabTitlebarItem::new(&workspace_handle, app_state.user_store.clone(), cx)
+    });
     workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
 
     let project_panel = ProjectPanel::new(workspace.project().clone(), cx);