Keep workspaces responsive across app-wide routes (#2791)
* perf(app): retain inactive workspace screens App-wide routes cleared the active workspace selection, which removed the retained workspace deck from the React tree and made returning rebuild every panel. Keep mounted deck entries inactive across those routes and suspend inactive panel subscriptions so state is preserved without background work. * perf(app): suspend remaining inactive queries Retained composers and commit diff panels still subscribed through query hooks that did not receive panel activity. Propagate the existing activity gate so app-wide routes leave those hidden surfaces dormant. * refactor(app): separate panel activity from connectivity A hidden retained panel is still connected to its host. Keep connectivity truthful, pause work inside query and stream owners, and preserve terminal emulator identity while its stream is detached. * test(app): target active retained controls * fix(app): retain compact and terminal route content * fix(app): hide inactive workspace overlays
This commit is contained in:
@@ -3,6 +3,7 @@ import type { ActiveWorkspaceSelection } from "@/stores/navigation-active-worksp
|
||||
import {
|
||||
orderWorkspaceSelectionsForStableRender,
|
||||
pruneMountedWorkspaceSelections,
|
||||
resolveWorkspaceDeckEntries,
|
||||
shouldKeepWorkspaceDeckEntryMounted,
|
||||
} from "@/screens/workspace/workspace-deck-retention";
|
||||
|
||||
@@ -92,6 +93,20 @@ describe("orderWorkspaceSelectionsForStableRender", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveWorkspaceDeckEntries", () => {
|
||||
it("keeps retained workspaces rendered but inactive on an app-wide route", () => {
|
||||
expect(
|
||||
resolveWorkspaceDeckEntries({
|
||||
selections: [workspace("A"), workspace("B")],
|
||||
activeSelection: null,
|
||||
}),
|
||||
).toEqual([
|
||||
{ selection: workspace("A"), active: false },
|
||||
{ selection: workspace("B"), active: false },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldKeepWorkspaceDeckEntryMounted", () => {
|
||||
it("keeps the active workspace mounted even when it is missing from hydrated workspaces", () => {
|
||||
expect(
|
||||
|
||||
@@ -14,6 +14,11 @@ interface WorkspaceDeckEntryMountInput {
|
||||
workspaceExists: boolean;
|
||||
}
|
||||
|
||||
interface ResolveWorkspaceDeckEntriesInput {
|
||||
selections: ActiveWorkspaceSelection[];
|
||||
activeSelection: ActiveWorkspaceSelection | null;
|
||||
}
|
||||
|
||||
export function getWorkspaceSelectionKey(selection: ActiveWorkspaceSelection): string {
|
||||
return `${selection.serverId}:${selection.workspaceId}`;
|
||||
}
|
||||
@@ -82,6 +87,19 @@ export function orderWorkspaceSelectionsForStableRender(
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveWorkspaceDeckEntries({
|
||||
selections,
|
||||
activeSelection,
|
||||
}: ResolveWorkspaceDeckEntriesInput): Array<{
|
||||
selection: ActiveWorkspaceSelection;
|
||||
active: boolean;
|
||||
}> {
|
||||
return selections.map((selection) => ({
|
||||
selection,
|
||||
active: areWorkspaceSelectionsEqual(selection, activeSelection),
|
||||
}));
|
||||
}
|
||||
|
||||
export function shouldKeepWorkspaceDeckEntryMounted({
|
||||
isActive,
|
||||
hasHydratedWorkspaces,
|
||||
|
||||
@@ -102,7 +102,7 @@ import {
|
||||
useHostRuntimeSnapshot,
|
||||
useHosts,
|
||||
} from "@/runtime/host-runtime";
|
||||
import { useProvidersSnapshot } from "@/hooks/use-providers-snapshot";
|
||||
import { prefetchProvidersSnapshot } from "@/hooks/use-providers-snapshot";
|
||||
import { shouldShowWorkspaceSetup, useWorkspaceSetupStore } from "@/stores/workspace-setup-store";
|
||||
import { useWorkspace } from "@/stores/session-store-hooks";
|
||||
import { useWorkspaceTerminalSessionRetention } from "@/terminal/hooks/use-workspace-terminal-session-retention";
|
||||
@@ -1770,6 +1770,9 @@ function WorkspaceScreenContent({
|
||||
|
||||
const client = useHostRuntimeClient(normalizedServerId);
|
||||
const isConnected = useHostRuntimeIsConnected(normalizedServerId);
|
||||
const supportsProvidersSnapshot = useSessionStore(
|
||||
(state) => state.sessions[normalizedServerId]?.serverInfo?.features?.providersSnapshot === true,
|
||||
);
|
||||
const workspaceDirectory = workspaceDescriptor?.workspaceDirectory || null;
|
||||
const isMissingWorkspaceDirectory = Boolean(workspaceDescriptor) && !workspaceDirectory;
|
||||
const [isImportSheetVisible, setIsImportSheetVisible] = useState(false);
|
||||
@@ -1781,11 +1784,25 @@ function WorkspaceScreenContent({
|
||||
setIsImportSheetVisible(false);
|
||||
}, []);
|
||||
|
||||
// Warm the workspace-scoped provider snapshot so the model picker is ready when opened.
|
||||
useProvidersSnapshot(normalizedServerId, {
|
||||
cwd: workspaceDirectory,
|
||||
enabled: isRouteFocused,
|
||||
});
|
||||
useEffect(() => {
|
||||
if (
|
||||
!isRouteFocused ||
|
||||
!isConnected ||
|
||||
!client ||
|
||||
!workspaceDirectory ||
|
||||
!supportsProvidersSnapshot
|
||||
) {
|
||||
return;
|
||||
}
|
||||
prefetchProvidersSnapshot(normalizedServerId, client, { cwd: workspaceDirectory });
|
||||
}, [
|
||||
client,
|
||||
isConnected,
|
||||
isRouteFocused,
|
||||
normalizedServerId,
|
||||
supportsProvidersSnapshot,
|
||||
workspaceDirectory,
|
||||
]);
|
||||
|
||||
const persistenceKey = useMemo(
|
||||
() =>
|
||||
@@ -3870,7 +3887,7 @@ function WorkspaceScreenContent({
|
||||
{workspaceCenterColumn}
|
||||
</WorkspaceChromeRow>
|
||||
<ImportSessionSheet
|
||||
visible={isImportSheetVisible}
|
||||
visible={isRouteFocused && isImportSheetVisible}
|
||||
client={client}
|
||||
serverId={normalizedServerId}
|
||||
cwd={workspaceDirectory}
|
||||
@@ -3879,7 +3896,7 @@ function WorkspaceScreenContent({
|
||||
onImportedAgent={handleImportedAgent}
|
||||
/>
|
||||
<WorkspaceTabRenameModal
|
||||
renamingTab={renamingTab}
|
||||
renamingTab={isRouteFocused ? renamingTab : null}
|
||||
onSubmit={handleRenameModalSubmit}
|
||||
onClose={handleRenameModalClose}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user