diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 31c796b200cc84d062cad6f404dd7ec4736453a4..450a2674e0062d917003758c41c445048ee603f7 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -3601,7 +3601,9 @@ impl WorkspaceSidebar for Sidebar { .map(|(s, count)| (PathList::deserialize(&s), count)) .collect(); if serialized.active_view == SerializedSidebarView::Archive { - self.show_archive(window, cx); + cx.defer_in(window, |this, window, cx| { + this.show_archive(window, cx); + }); } } cx.notify(); diff --git a/crates/sidebar/src/sidebar_tests.rs b/crates/sidebar/src/sidebar_tests.rs index 18fa8c9375c8d9c30ca3c1369613c0385f1cc94d..d0400d1ae4338ac5de4dfee0daca9196f12030b5 100644 --- a/crates/sidebar/src/sidebar_tests.rs +++ b/crates/sidebar/src/sidebar_tests.rs @@ -322,6 +322,41 @@ async fn test_serialization_round_trip(cx: &mut TestAppContext) { assert_eq!(expanded1.get(&path_list), Some(&2)); } +#[gpui::test] +async fn test_restore_serialized_archive_view_does_not_panic(cx: &mut TestAppContext) { + // A regression test to ensure that restoring a serialized archive view does not panic. + let project = init_test_project_with_agent_panel("/my-project", cx).await; + let (multi_workspace, cx) = + cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx)); + let (sidebar, _panel) = setup_sidebar_with_agent_panel(&multi_workspace, cx); + cx.update(|_window, cx| { + AgentRegistryStore::init_test_global(cx, vec![]); + }); + + let serialized = serde_json::to_string(&SerializedSidebar { + width: Some(400.0), + collapsed_groups: Vec::new(), + expanded_groups: Vec::new(), + active_view: SerializedSidebarView::Archive, + }) + .expect("serialization should succeed"); + + multi_workspace.update_in(cx, |multi_workspace, window, cx| { + if let Some(sidebar) = multi_workspace.sidebar() { + sidebar.restore_serialized_state(&serialized, window, cx); + } + }); + cx.run_until_parked(); + + // After the deferred `show_archive` runs, the view should be Archive. + sidebar.read_with(cx, |sidebar, _cx| { + assert!( + matches!(sidebar.view, SidebarView::Archive(_)), + "expected sidebar view to be Archive after restore, got ThreadList" + ); + }); +} + #[test] fn test_clean_mention_links() { // Simple mention link