1- import { useState , useEffect , useCallback , useRef } from "react" ;
1+ import { useState , useEffect , useCallback , useRef , useMemo } from "react" ;
22import styled from "@emotion/styled" ;
33import { Global , css } from "@emotion/react" ;
44import { GlobalColors } from "./styles/colors" ;
55import { GlobalFonts } from "./styles/fonts" ;
66import { GlobalScrollbars } from "./styles/scrollbars" ;
77import type { ProjectConfig } from "./config" ;
88import type { WorkspaceSelection } from "./components/ProjectSidebar" ;
9+ import type { WorkspaceMetadataWithPaths } from "./types/workspace" ;
910import { LeftSidebar } from "./components/LeftSidebar" ;
1011import NewWorkspaceModal from "./components/NewWorkspaceModal" ;
1112import { AIView } from "./components/AIView" ;
@@ -172,6 +173,17 @@ function AppInner() {
172173 onSelectedWorkspaceUpdate : setSelectedWorkspace ,
173174 } ) ;
174175
176+ // Build path-to-metadata lookup map (handles both stable and legacy paths)
177+ const pathToMetadata = useMemo ( ( ) => {
178+ const map = new Map < string , WorkspaceMetadataWithPaths > ( ) ;
179+ for ( const metadata of workspaceMetadata . values ( ) ) {
180+ // Map both stable path (with ID) and named path (with name/legacy)
181+ map . set ( metadata . stableWorkspacePath , metadata ) ;
182+ map . set ( metadata . namedWorkspacePath , metadata ) ;
183+ }
184+ return map ;
185+ } , [ workspaceMetadata ] ) ;
186+
175187 // NEW: Sync workspace metadata with the stores
176188 const workspaceStore = useWorkspaceStoreRaw ( ) ;
177189 const gitStatusStore = useGitStatusStoreRaw ( ) ;
@@ -321,11 +333,9 @@ function AppInner() {
321333 result . set (
322334 projectPath ,
323335 config . workspaces . slice ( ) . sort ( ( a , b ) => {
324- // Extract workspace ID from path
325- const aId = a . path . replace ( / \\ / g, "/" ) . split ( "/" ) . pop ( ) ?? "" ;
326- const bId = b . path . replace ( / \\ / g, "/" ) . split ( "/" ) . pop ( ) ?? "" ;
327- const aMeta = workspaceMetadata . get ( aId ) ;
328- const bMeta = workspaceMetadata . get ( bId ) ;
336+ // Look up metadata by workspace path (handles both stable and legacy paths)
337+ const aMeta = pathToMetadata . get ( a . path ) ;
338+ const bMeta = pathToMetadata . get ( b . path ) ;
329339 if ( ! aMeta || ! bMeta ) return 0 ;
330340
331341 // Get timestamp of most recent user message (0 if never used)
@@ -349,7 +359,7 @@ function AppInner() {
349359 }
350360 return true ;
351361 } ,
352- [ projects , workspaceMetadata , workspaceRecency ]
362+ [ projects , workspaceMetadata , workspaceRecency , pathToMetadata ]
353363 ) ;
354364
355365 const handleNavigateWorkspace = useCallback (
@@ -377,9 +387,8 @@ function AppInner() {
377387 const targetWorkspace = sortedWorkspaces [ targetIndex ] ;
378388 if ( ! targetWorkspace ) return ;
379389
380- // Extract workspace ID from path
381- const workspaceId = targetWorkspace . path . replace ( / \\ / g, "/" ) . split ( "/" ) . pop ( ) ?? "" ;
382- const metadata = workspaceMetadata . get ( workspaceId ) ;
390+ // Look up metadata by workspace path (handles both stable and legacy paths)
391+ const metadata = pathToMetadata . get ( targetWorkspace . path ) ;
383392 if ( ! metadata ) return ;
384393
385394 setSelectedWorkspace ( {
@@ -389,7 +398,7 @@ function AppInner() {
389398 workspaceId : metadata . id ,
390399 } ) ;
391400 } ,
392- [ selectedWorkspace , sortedWorkspacesByProject , workspaceMetadata , setSelectedWorkspace ]
401+ [ selectedWorkspace , sortedWorkspacesByProject , pathToMetadata , setSelectedWorkspace ]
393402 ) ;
394403
395404 // Register command sources with registry
0 commit comments