* 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
105 lines
3.5 KiB
TypeScript
105 lines
3.5 KiB
TypeScript
import { useMemo } from "react";
|
|
import { useRetainedPanelActive } from "@/components/retained-panel";
|
|
import { useReplicaQuery } from "@/data/query";
|
|
import { checkoutDiffPushRoute } from "@/data/push-router";
|
|
import { useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
|
import type { ParsedDiffFile, SubscribeCheckoutDiffResponse } from "@getpaseo/protocol/messages";
|
|
import { checkoutDiffQueryKey } from "@/git/query-keys";
|
|
|
|
interface UseCheckoutDiffQueryOptions {
|
|
serverId: string;
|
|
cwd: string;
|
|
mode: "uncommitted" | "base";
|
|
baseRef?: string;
|
|
ignoreWhitespace?: boolean;
|
|
enabled?: boolean;
|
|
queryScope?: string;
|
|
}
|
|
|
|
type CheckoutDiffQueryPayload = Omit<SubscribeCheckoutDiffResponse["payload"], "subscriptionId">;
|
|
|
|
// Re-export the canonical protocol type so all consumers share one definition.
|
|
export type { ParsedDiffFile };
|
|
export type DiffHunk = ParsedDiffFile["hunks"][number];
|
|
export type DiffLine = DiffHunk["lines"][number];
|
|
export type HighlightToken = NonNullable<DiffLine["tokens"]>[number];
|
|
|
|
function normalizeCheckoutDiffCompare(compare: {
|
|
mode: "uncommitted" | "base";
|
|
baseRef?: string;
|
|
ignoreWhitespace?: boolean;
|
|
}): { mode: "uncommitted" | "base"; baseRef?: string; ignoreWhitespace?: boolean } {
|
|
const ignoreWhitespace = compare.ignoreWhitespace === true;
|
|
if (compare.mode === "uncommitted") {
|
|
return { mode: "uncommitted", ignoreWhitespace };
|
|
}
|
|
const trimmedBaseRef = compare.baseRef?.trim();
|
|
return trimmedBaseRef
|
|
? { mode: "base", baseRef: trimmedBaseRef, ignoreWhitespace }
|
|
: { mode: "base", ignoreWhitespace };
|
|
}
|
|
|
|
export function useCheckoutDiffQuery({
|
|
serverId,
|
|
cwd,
|
|
mode,
|
|
baseRef,
|
|
ignoreWhitespace,
|
|
enabled = true,
|
|
queryScope,
|
|
}: UseCheckoutDiffQueryOptions) {
|
|
const retainedPanelActive = useRetainedPanelActive();
|
|
const queryEnabled = enabled && retainedPanelActive;
|
|
const isConnected = useHostRuntimeIsConnected(serverId);
|
|
const normalizedCompare = useMemo(
|
|
() => normalizeCheckoutDiffCompare({ mode, baseRef, ignoreWhitespace }),
|
|
[mode, baseRef, ignoreWhitespace],
|
|
);
|
|
const compareMode = normalizedCompare.mode;
|
|
const compareBaseRef = normalizedCompare.baseRef;
|
|
const compareIgnoreWhitespace = normalizedCompare.ignoreWhitespace;
|
|
const queryKey = useMemo(() => {
|
|
const comparisonKey = checkoutDiffQueryKey(
|
|
serverId,
|
|
cwd,
|
|
compareMode,
|
|
compareBaseRef,
|
|
compareIgnoreWhitespace,
|
|
);
|
|
const normalizedScope = queryScope?.trim();
|
|
return normalizedScope ? [...comparisonKey, "scope", normalizedScope] : comparisonKey;
|
|
}, [serverId, cwd, compareMode, compareBaseRef, compareIgnoreWhitespace, queryScope]);
|
|
const subscriptionId = useMemo(() => `checkoutDiff:${JSON.stringify(queryKey)}`, [queryKey]);
|
|
const routeEnabled = Boolean(queryEnabled && isConnected && cwd);
|
|
|
|
const query = useReplicaQuery<CheckoutDiffQueryPayload>({
|
|
queryKey,
|
|
enabled: routeEnabled,
|
|
pushEvent: "checkout_diff_update",
|
|
meta: checkoutDiffPushRoute({
|
|
enabled: routeEnabled,
|
|
serverId,
|
|
subscriptionId,
|
|
cwd,
|
|
compare: {
|
|
mode: compareMode,
|
|
...(compareBaseRef ? { baseRef: compareBaseRef } : {}),
|
|
ignoreWhitespace: compareIgnoreWhitespace,
|
|
},
|
|
}),
|
|
});
|
|
|
|
const payload = query.data ?? null;
|
|
const payloadError = payload?.error ?? null;
|
|
|
|
return {
|
|
files: payload?.files ?? [],
|
|
payloadError,
|
|
diffTooLarge: payload?.diffTooLarge === true,
|
|
isLoading: payload === null && queryEnabled && isConnected,
|
|
isFetching: false,
|
|
isError: Boolean(payloadError),
|
|
error: null,
|
|
};
|
|
}
|