Keep New Workspace on the current project (#1806)

* fix(app): keep New Workspace on the active project

New Workspace preselection was falling back to stale remembered host state when multiple hosts existed. Pass durable active-project context from workspace entry points and centralize initial host selection so stale offline hosts cannot steal the form while startup restore remains last-workspace only.

* fix(app): address New Workspace review feedback

* fix(app): stabilize New Workspace host selection

* fix(app): preserve New Workspace host fallback

* test(app): loosen stale-host project assertion

* fix(app): prefer reachable new workspace hosts

* fix(app): avoid stale offline workspace preselect

* fix(app): prefer online project hosts
This commit is contained in:
Mohamed Boudra
2026-06-29 20:44:18 +02:00
committed by GitHub
parent 0614618d2f
commit f94ec0e430
13 changed files with 1171 additions and 116 deletions
+25
View File
@@ -1,4 +1,7 @@
import { useMemo } from "react";
import { useShallow } from "zustand/shallow";
import type { DaemonServerInfo } from "@/stores/session-store";
import { useSessionStore } from "@/stores/session-store";
export type HostFeatureName = keyof NonNullable<DaemonServerInfo["features"]>;
@@ -26,3 +29,25 @@ export function selectHostFeature(
): boolean {
return hostSupportsFeature(state.sessions[serverId]?.serverInfo, feature);
}
export function useHostFeature(
serverId: string | null | undefined,
feature: HostFeatureName,
): boolean {
const normalizedServerId = serverId?.trim() ?? "";
return useSessionStore((state) => selectHostFeature(state, normalizedServerId, feature));
}
export function useHostFeatureMap(
serverIds: readonly string[],
feature: HostFeatureName,
): ReadonlyMap<string, boolean> {
const flags = useSessionStore(
useShallow((state) => serverIds.map((serverId) => selectHostFeature(state, serverId, feature))),
);
return useMemo(
() => new Map(serverIds.map((serverId, index) => [serverId, flags[index] === true] as const)),
[flags, serverIds],
);
}
+22
View File
@@ -2202,6 +2202,28 @@ export function useHostRuntimeConnectionStatus(serverId: string): HostRuntimeCon
);
}
export function useHostRuntimeConnectionStatuses(
serverIds: readonly string[],
): ReadonlyMap<string, HostRuntimeConnectionStatus> {
const store = getHostRuntimeStore();
const version = useSyncExternalStore(
(onStoreChange) => store.subscribeAll(onStoreChange),
() => store.getVersion(),
() => store.getVersion(),
);
return useMemo(() => {
// The aggregate version is the reactivity trigger; re-read snapshots on every host tick.
void version;
return new Map(
serverIds.map(
(serverId) =>
[serverId, store.getSnapshot(serverId)?.connectionStatus ?? "connecting"] as const,
),
);
}, [serverIds, store, version]);
}
export function useHostRuntimeLastError(serverId: string): string | null {
const store = getHostRuntimeStore();
return useSyncExternalStore(