fix(snapshot): normalize renderer:get-last-opened-workspaces output to avoid reactivating a deleted workspace (#8033)

* fix: normalize workspace paths during workspace switch to prevent stale state

* chore: test text

* tests(snapshot): more workspace coverage
This commit is contained in:
Sid
2026-05-18 21:24:58 +05:30
committed by GitHub
parent e8468ac9a5
commit cea883eda2
3 changed files with 304 additions and 2 deletions

View File

@@ -808,6 +808,7 @@ export const workspaceOpenedEvent = (workspacePath, workspaceUid, workspaceConfi
try {
const snapshot = await ipcRenderer.invoke('renderer:snapshot:get');
const activeWorkspacePath = snapshot?.activeWorkspacePath;
const normalizedWorkspacePath = normalizePath(workspacePath || '');
const currentState = getState();
if (!currentState.app.snapshotReady && snapshot?.extras?.devTools) {
@@ -822,7 +823,23 @@ export const workspaceOpenedEvent = (workspacePath, workspaceUid, workspaceConfi
}
if (activeWorkspacePath) {
shouldSwitch = workspacePath === activeWorkspacePath;
const normalizedActiveWorkspacePath = normalizePath(activeWorkspacePath);
shouldSwitch = normalizedWorkspacePath === normalizedActiveWorkspacePath;
// If the snapshot points to a workspace that no longer exists on disk,
// fall back to the default workspace instead of leaving stale active state.
if (!shouldSwitch && workspaceConfig.type === 'default') {
const lastOpenedWorkspacePaths = await ipcRenderer.invoke('renderer:get-last-opened-workspaces').catch(() => []);
const normalizedLastOpenedWorkspacePaths = new Set(
(Array.isArray(lastOpenedWorkspacePaths) ? lastOpenedWorkspacePaths : [])
.map((pathname) => normalizePath(pathname))
);
const hasActiveWorkspacePath = normalizedLastOpenedWorkspacePaths.has(normalizedActiveWorkspacePath);
if (!hasActiveWorkspacePath) {
shouldSwitch = true;
}
}
} else {
shouldSwitch = !activeWorkspaceUid || workspaceConfig.type === 'default';
}