Skip to content

Commit a158363

Browse files
committed
Fix stuck loading state for deleted/invalid workspaces
When a workspace is deleted or doesn't exist: - Previously: selectedWorkspace persisted in localStorage, causing eternal "Loading workspace..." - Now: Validate workspace exists on mount and clear invalid selection Added validation effect that: - Checks if selected workspace ID exists in workspaceMetadata - Clears selection if workspace was deleted - Also clears URL hash to prevent re-selection on reload Fixes edge cases: - Workspace deleted while app was closed - URL with invalid workspace ID (#workspace=invalid-id) - Workspace removed from another instance
1 parent 4e48861 commit a158363

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/App.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,23 @@ function AppInner() {
255255
// eslint-disable-next-line react-hooks/exhaustive-deps
256256
}, []);
257257

258+
// Validate selected workspace exists (clear if workspace was deleted)
259+
useEffect(() => {
260+
if (selectedWorkspace && workspaceMetadata.size > 0) {
261+
const exists = workspaceMetadata.has(selectedWorkspace.workspaceId);
262+
if (!exists) {
263+
console.warn(
264+
`Workspace ${selectedWorkspace.workspaceId} no longer exists, clearing selection`
265+
);
266+
setSelectedWorkspace(null);
267+
// Also clear URL hash if present
268+
if (window.location.hash) {
269+
window.history.replaceState(null, "", window.location.pathname);
270+
}
271+
}
272+
}
273+
}, [selectedWorkspace, workspaceMetadata, setSelectedWorkspace]);
274+
258275
const openWorkspaceInTerminal = useCallback((workspacePath: string) => {
259276
void window.api.workspace.openTerminal(workspacePath);
260277
}, []);

0 commit comments

Comments
 (0)