Skip to content

Commit 6954918

Browse files
committed
🤖 Fix workspace deletion UI crash with layered null checks
- Primary fix: Handle null metadata in onMetadata subscription (delete from map) - Defense: Add null check to filter in sortedWorkspacesByProject - Safety: Add null guard in metadata comparison function Prevents crash when deleting workspace by ensuring null metadata never pollutes the state Map or reaches comparison logic.
1 parent a162a48 commit 6954918

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ function AppInner() {
419419
// Transform Workspace[] to FrontendWorkspaceMetadata[] using workspace ID
420420
const metadataList = config.workspaces
421421
.map((ws) => (ws.id ? workspaceMetadata.get(ws.id) : undefined))
422-
.filter((meta): meta is FrontendWorkspaceMetadata => meta !== undefined);
422+
.filter((meta): meta is FrontendWorkspaceMetadata => meta !== undefined && meta !== null);
423423

424424
// Sort by recency
425425
metadataList.sort((a, b) => {
@@ -440,7 +440,7 @@ function AppInner() {
440440
// Check both ID and name to detect renames
441441
return a.every((metadata, i) => {
442442
const bMeta = b[i];
443-
if (!bMeta) return false;
443+
if (!bMeta || !metadata) return false; // Null-safe
444444
return metadata.id === bMeta.id && metadata.name === bMeta.name;
445445
});
446446
})

src/hooks/useWorkspaceManagement.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ export function useWorkspaceManagement({
5252
// Subscribe to metadata updates (for create/rename/delete operations)
5353
useEffect(() => {
5454
const unsubscribe = window.api.workspace.onMetadata(
55-
(event: { workspaceId: string; metadata: FrontendWorkspaceMetadata }) => {
55+
(event: { workspaceId: string; metadata: FrontendWorkspaceMetadata | null }) => {
5656
setWorkspaceMetadata((prev) => {
5757
const updated = new Map(prev);
58-
updated.set(event.workspaceId, event.metadata);
58+
if (event.metadata === null) {
59+
// Workspace deleted - remove from map
60+
updated.delete(event.workspaceId);
61+
} else {
62+
updated.set(event.workspaceId, event.metadata);
63+
}
5964
return updated;
6065
});
6166
}

0 commit comments

Comments
 (0)