@@ -224,12 +224,15 @@ function AppInner() {
224224 } , [ selectedWorkspace ] ) ;
225225
226226 // Restore workspace from URL on mount (if valid)
227+ // This effect runs once on mount to restore from hash, which takes priority over localStorage
228+ const [ hasRestoredFromHash , setHasRestoredFromHash ] = useState ( false ) ;
229+
227230 useEffect ( ( ) => {
231+ // Only run once
232+ if ( hasRestoredFromHash ) return ;
233+
228234 // Wait for metadata to load before attempting restore
229235 if ( workspaceMetadata . size === 0 ) return ;
230-
231- // Only restore once - if workspace is already selected, skip
232- if ( selectedWorkspace ) return ;
233236
234237 const hash = window . location . hash ;
235238 if ( hash . startsWith ( "#workspace=" ) ) {
@@ -239,7 +242,7 @@ function AppInner() {
239242 const metadata = workspaceMetadata . get ( workspaceId ) ;
240243
241244 if ( metadata ) {
242- // Find project for this workspace (metadata now includes projectPath )
245+ // Restore from hash (overrides localStorage )
243246 setSelectedWorkspace ( {
244247 workspaceId : metadata . id ,
245248 projectPath : metadata . projectPath ,
@@ -248,7 +251,9 @@ function AppInner() {
248251 } ) ;
249252 }
250253 }
251- } , [ workspaceMetadata , selectedWorkspace , setSelectedWorkspace ] ) ;
254+
255+ setHasRestoredFromHash ( true ) ;
256+ } , [ workspaceMetadata , hasRestoredFromHash , setSelectedWorkspace ] ) ;
252257
253258 // Validate selected workspace exists and has all required fields
254259 useEffect ( ( ) => {
@@ -264,8 +269,8 @@ function AppInner() {
264269 if ( window . location . hash ) {
265270 window . history . replaceState ( null , "" , window . location . pathname ) ;
266271 }
267- } else if ( ! selectedWorkspace . namedWorkspacePath ) {
268- // Old localStorage entry missing namedWorkspacePath - update it
272+ } else if ( ! selectedWorkspace . namedWorkspacePath && metadata . namedWorkspacePath ) {
273+ // Old localStorage entry missing namedWorkspacePath - update it once
269274 console . log (
270275 `Updating workspace ${ selectedWorkspace . workspaceId } with missing fields`
271276 ) ;
@@ -377,9 +382,11 @@ function AppInner() {
377382 ! compareMaps ( prev , next , ( a , b ) => {
378383 if ( a . length !== b . length ) return false ;
379384 // Check both ID and name to detect renames
380- return a . every ( ( metadata , i ) =>
381- metadata . id === b [ i ] . id && metadata . name === b [ i ] . name
382- ) ;
385+ return a . every ( ( metadata , i ) => {
386+ const bMeta = b [ i ] ;
387+ if ( ! bMeta ) return false ;
388+ return metadata . id === bMeta . id && metadata . name === bMeta . name ;
389+ } ) ;
383390 } )
384391 ) {
385392 return false ;
0 commit comments