@@ -1214,11 +1214,28 @@ export default function Layout(props: ParentProps) {
12141214 }
12151215
12161216 function closeProject ( directory : string ) {
1217- const index = layout . projects . list ( ) . findIndex ( ( x ) => x . worktree === directory )
1218- const next = layout . projects . list ( ) [ index + 1 ]
1217+ const list = layout . projects . list ( )
1218+ const index = list . findIndex ( ( x ) => x . worktree === directory )
1219+ const active = currentProject ( ) ?. worktree === directory
1220+ if ( index === - 1 ) return
1221+ const next = list [ index + 1 ]
1222+
1223+ if ( ! active ) {
1224+ layout . projects . close ( directory )
1225+ return
1226+ }
1227+
1228+ if ( ! next ) {
1229+ layout . projects . close ( directory )
1230+ navigate ( "/" )
1231+ return
1232+ }
1233+
1234+ navigateWithSidebarReset ( `/${ base64Encode ( next . worktree ) } /session` )
12191235 layout . projects . close ( directory )
1220- if ( next ) navigateToProject ( next . worktree )
1221- else navigate ( "/" )
1236+ queueMicrotask ( ( ) => {
1237+ void navigateToProject ( next . worktree )
1238+ } )
12221239 }
12231240
12241241 function toggleProjectWorkspaces ( project : LocalProject ) {
@@ -2073,7 +2090,11 @@ export default function Layout(props: ParentProps) {
20732090 onOpenSettings = { openSettings }
20742091 helpLabel = { ( ) => language . t ( "sidebar.help" ) }
20752092 onOpenHelp = { ( ) => platform . openLink ( "https://opencode.ai/desktop-feedback" ) }
2076- renderPanel = { ( ) => < SidebarPanel project = { currentProject ( ) } /> }
2093+ renderPanel = { ( ) => (
2094+ < Show when = { currentProject ( ) } keyed >
2095+ { ( project ) => < SidebarPanel project = { project } /> }
2096+ </ Show >
2097+ ) }
20772098 />
20782099 </ div >
20792100 < Show when = { ! layout . sidebar . opened ( ) ? hoverProjectData ( ) ?. worktree : undefined } keyed >
0 commit comments