TypeScript
fix(clients): show unsupported environments as neutral rows with their machine icon (#12026)
Julius Marmingec1b2ed6504bb
diff --git a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsxindex 00518b97adb..b1748b1938c 100644--- a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx+++ b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx@@ -7,6 +7,7 @@ import {import {type EnvironmentId,type EnvironmentMachineKind,+ type ExecutionEnvironmentDescriptor,resolveEnvironmentMachineKind,} from "@t3tools/contracts";import { useAtomValue } from "@effect/atom-react";@@ -99,6 +100,16 @@ function CloudEnvironmentRowsContent([controller],);+ // The relay's health probe carries each server's descriptor, so a machine+ // can wear its detected glyph before this device ever connects to it.+ const discoveredDescriptors = new Map(+ controller.relayEnvironments.flatMap((entry) =>+ entry.status?.descriptor === undefined+ ? []+ : [[entry.environment.environmentId, entry.status.descriptor] as const],+ ),+ );+const handleToggleCloudError = useCallback((environmentId: string) => {setExpandedErrorId((current) => (current === environmentId ? null : environmentId));}, []);@@ -140,6 +151,7 @@ function CloudEnvironmentRowsContent(<ConnectedCloudEnvironmentRowkey={environment.environmentId}environment={environment}+ descriptor={discoveredDescriptors.get(environment.environmentId)}borderTop={index !== 0}onSetEnabled={(enabled) =>props.onSetEnvironmentEnabled(environment.environmentId, enabled)@@ -210,6 +222,8 @@ function CloudEnvironmentRowsContent(*/function ConnectedCloudEnvironmentRow(props: {readonly environment: ConnectedEnvironmentSummary;+ /** Discovery's view of the server, for the glyph before the first connection. */+ readonly descriptor: ExecutionEnvironmentDescriptor | undefined;readonly borderTop: boolean;readonly errorExpanded: boolean;readonly onSetEnabled: (enabled: boolean) => void;@@ -233,7 +247,10 @@ function ConnectedCloudEnvironmentRow(props: {connectionState={enabled || unsupported ? props.environment.connectionState : "available"}errorExpanded={props.errorExpanded}label={props.environment.environmentLabel}- machine={resolveEnvironmentMachineKind(serverConfig)}+ machine={resolveEnvironmentMachineKind(+ serverConfig ??+ (props.descriptor === undefined ? null : { environment: props.descriptor }),+ )}onValueChange={props.onSetEnabled}onToggleError={props.onToggleError}disabled={unsupported}@@ -266,6 +283,11 @@ function CloudEnvironmentRow(props: {connectionState={presentation.connectionState}errorExpanded={props.errorExpanded}label={props.environment.environment.label}+ machine={resolveEnvironmentMachineKind(+ props.environment.status?.descriptor === undefined+ ? null+ : { environment: props.environment.status.descriptor },+ )}onValueChange={(enabled) => {if (enabled) {props.onConnect();@@ -287,8 +309,7 @@ function CloudEnvironmentRowShell(props: {readonly disabled?: boolean;readonly errorExpanded: boolean;readonly label: string;- /** Absent for environments the relay lists but this device has not connected to. */- readonly machine?: EnvironmentMachineKind;+ readonly machine: EnvironmentMachineKind;readonly onToggleError: () => void;readonly onValueChange: (enabled: boolean) => void;readonly statusText?: string;@@ -304,9 +325,11 @@ function CloudEnvironmentRowShell(props: {error: props.connectionError,traceId: props.connectionErrorTraceId,});- const statusClassName = props.connectionError- ? "text-danger-foreground"- : "text-foreground-muted";+ // Unsupported is a compatibility note, not a failure, so it stays muted.+ const statusClassName =+ props.connectionError && props.connectionState !== "unsupported"+ ? "text-danger-foreground"+ : "text-foreground-muted";const [errorMeasurement, setErrorMeasurement] = useState<{readonly text: string;readonly lineCount: number;@@ -344,13 +367,11 @@ function CloudEnvironmentRowShell(props: {<View className="min-w-0 flex-1 gap-0.5"><View className="min-w-0 flex-row items-center gap-2"><ConnectionStatusDot state={props.connectionState} pulse={shouldPulse} size={7} />- {props.machine ? (- <EnvironmentMachineSymbol- kind={props.machine}- size={14}- tintColorClassName="accent-foreground-muted"- />- ) : null}+ <EnvironmentMachineSymbol+ kind={props.machine}+ size={14}+ tintColorClassName="accent-foreground-muted"+ /><TextclassName="min-w-0 flex-shrink text-base font-t3-bold leading-snug text-foreground"numberOfLines={1}diff --git a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsxindex f572cec33db..42d9cdddd0e 100644--- a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx+++ b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx@@ -50,8 +50,8 @@ export function ConnectionEnvironmentRow(props: {const enabled = props.environment.isEnabled && !unsupported;const statusLabel = connectionStatusLabel(props.environment);const statusTraceId = enabled ? props.environment.connectionErrorTraceId : null;- const hasConnectionFailure =- (enabled || unsupported) && props.environment.connectionError !== null;+ // Unsupported is a compatibility note, not a failure, so it stays muted.+ const hasConnectionFailure = enabled && props.environment.connectionError !== null;const isRetrying =enabled &&(props.environment.connectionState === "connecting" ||diff --git a/apps/mobile/src/features/connection/ConnectionStatusDot.tsx b/apps/mobile/src/features/connection/ConnectionStatusDot.tsxindex beed3f99e17..43c61249a74 100644--- a/apps/mobile/src/features/connection/ConnectionStatusDot.tsx+++ b/apps/mobile/src/features/connection/ConnectionStatusDot.tsx@@ -18,7 +18,10 @@ function statusDotTone(state: ConnectionStatusDotState): {readonly haloColor: string;} {switch (state) {+ // Unsupported is not a failure: the machine is fine, this build just+ // cannot talk to it, so it wears the same neutral dot as "available".case "available":+ case "unsupported":return {dotColor: "#9ca3af",haloColor: "rgba(156,163,175,0.42)",@@ -35,7 +38,6 @@ function statusDotTone(state: ConnectionStatusDotState): {haloColor: "rgba(245,158,11,0.5)",};case "offline":- case "unsupported":case "error":return {dotColor: "#ef4444",diff --git a/apps/mobile/src/features/connection/connectionTone.ts b/apps/mobile/src/features/connection/connectionTone.tsindex 4a005aae671..05a65408567 100644--- a/apps/mobile/src/features/connection/connectionTone.ts+++ b/apps/mobile/src/features/connection/connectionTone.ts@@ -24,8 +24,8 @@ export function connectionTone(state: RemoteClientConnectionState): StatusTone {case "unsupported":return {label: "Client not supported",- pillClassName: "bg-danger",- textClassName: "text-danger-foreground",+ pillClassName: "bg-subtle",+ textClassName: "text-foreground-secondary",};case "error":return {diff --git a/apps/web/src/components/ConnectionStatusDot.tsx b/apps/web/src/components/ConnectionStatusDot.tsxindex 382e6d25b86..6a23a053287 100644--- a/apps/web/src/components/ConnectionStatusDot.tsx+++ b/apps/web/src/components/ConnectionStatusDot.tsx@@ -11,7 +11,6 @@ export function connectionPhaseDotClassName(phase: EnvironmentConnectionPhase):case "connecting":case "reconnecting":return "bg-warning";- case "unsupported":case "error":return "bg-destructive";default:diff --git a/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx b/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsxindex 1fe874d249e..5d4e002cf86 100644--- a/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx+++ b/apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx@@ -9,7 +9,11 @@ import {isAtomCommandInterrupted,squashAtomCommandFailure,} from "@t3tools/client-runtime/state/runtime";-import type { EnvironmentId } from "@t3tools/contracts";+import {+ type EnvironmentId,+ resolveEnvironmentMachineKind,+ type ServerConfig,+} from "@t3tools/contracts";import type {RelayClientEnvironmentRecord,RelayEnvironmentStatusResponse,@@ -23,6 +27,7 @@ import { relayEnvironmentDiscovery } from "~/state/relay";import { useRelayEnvironmentDiscovery } from "~/state/environments";import { useAtomCommand } from "~/state/use-atom-command";import { ConnectionStatusDot } from "../ConnectionStatusDot";+import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";import { ITEM_ROW_CLASSNAME, ITEM_ROW_INNER_CLASSNAME } from "../settings/itemRows";import { Checkbox } from "../ui/checkbox";import { Button } from "../ui/button";@@ -43,6 +48,8 @@ function discoveredCompatibilityError(export interface SavedCloudEnvironmentConnection {readonly environmentId: EnvironmentId;readonly connection: EnvironmentConnectionPresentation;+ /** Present once connected; carries the user's icon override. */+ readonly serverConfig?: ServerConfig | null;}function RemoteEnvironmentRowsSkeleton() {@@ -296,15 +303,25 @@ export function CloudEnvironmentConnectRows({const compatibilityError = discoveredCompatibilityError(status);const unsupported =compatibilityError !== null || savedEnvironment?.connection.phase === "unsupported";+ const unsupportedDetail =+ compatibilityError?.message ?? savedEnvironment?.connection.error ?? null;const savedConnection = unsupported? presentSavedCloudEnvironmentConnection({phase: "unsupported",- error: compatibilityError?.message ?? savedEnvironment?.connection.error ?? null,+ error: unsupportedDetail,traceId: null,}): savedEnvironment? presentSavedCloudEnvironmentConnection(savedEnvironment.connection): null;+ // A connected machine's own config (with the user's icon pick) wins. Before+ // that, the relay's health probe already carries the server's descriptor, so+ // a machine can wear its detected glyph before this device ever connects.+ const descriptor = status === undefined ? undefined : Option.getOrNull(status)?.descriptor;+ const machineKind = resolveEnvironmentMachineKind(+ savedEnvironment?.serverConfig ??+ (descriptor === undefined ? null : { environment: descriptor }),+ );const dotClassName = savedConnection? savedConnection.tone === "connected"? "bg-success"@@ -320,16 +337,19 @@ export function CloudEnvironmentConnectRows({: availability === "checking"? "bg-warning": "bg-muted-foreground/35";- const statusText = savedConnection- ? savedConnection.statusText- : availability === "online"- ? "T3 Connect · Not added · Relay online"- : availability === "offline"- ? "T3 Connect · Not added · Relay offline"- : availability === "checking"- ? "T3 Connect · Not added · Checking relay status…"- : (Option.getOrNull(error)?.message ??- "T3 Connect · Not added · Relay status unavailable");+ const statusText =+ unsupported && !savedEnvironment+ ? "T3 Connect · Not added · Client not supported"+ : savedConnection+ ? savedConnection.statusText+ : availability === "online"+ ? "T3 Connect · Not added · Relay online"+ : availability === "offline"+ ? "T3 Connect · Not added · Relay offline"+ : availability === "checking"+ ? "T3 Connect · Not added · Checking relay status…"+ : (Option.getOrNull(error)?.message ??+ "T3 Connect · Not added · Relay status unavailable");if (selection) {return (<label@@ -348,6 +368,11 @@ export function CloudEnvironmentConnectRows({}}}/>+ <EnvironmentMachineIcon+ aria-hidden+ kind={machineKind}+ className="size-4 shrink-0 text-muted-foreground"+ /><span className="min-w-0 flex-1 truncate text-sm font-medium">{environment.label}</span><Tooltip><TooltipTrigger@@ -368,7 +393,9 @@ export function CloudEnvironmentConnectRows({? "Unavailable": "Checking…"))}</TooltipTrigger>- <TooltipPopup className="max-w-80 break-words">{statusText}</TooltipPopup>+ <TooltipPopup className="max-w-80 break-words">+ {unsupportedDetail ?? statusText}+ </TooltipPopup></Tooltip></label>);@@ -387,17 +414,24 @@ export function CloudEnvironmentConnectRows({: null}tooltipText={- savedConnection- ? savedConnection.statusText- : availability === "online"- ? "Relay online"- : availability === "offline"- ? "Relay offline"- : availability === "checking"- ? "Checking relay status"- : (Option.getOrNull(error)?.message ?? "Relay status unavailable")+ unsupportedDetail !== null+ ? unsupportedDetail+ : savedConnection+ ? savedConnection.statusText+ : availability === "online"+ ? "Relay online"+ : availability === "offline"+ ? "Relay offline"+ : availability === "checking"+ ? "Checking relay status"+ : (Option.getOrNull(error)?.message ?? "Relay status unavailable")}/>+ <EnvironmentMachineIcon+ aria-hidden+ kind={machineKind}+ className="size-4 shrink-0 text-muted-foreground"+ /><p className="truncate text-sm font-medium">{environment.label}</p></div><p@@ -413,7 +447,18 @@ export function CloudEnvironmentConnectRows({{statusText}</p></div>- {savedConnection ? (+ {unsupported && !savedEnvironment ? (+ <Tooltip>+ <TooltipTrigger render={<span className="inline-flex" tabIndex={0} />}>+ <Button size="sm" disabled>+ Add+ </Button>+ </TooltipTrigger>+ <TooltipPopup className="max-w-80 break-words">+ {unsupportedDetail ?? "Client not supported"}+ </TooltipPopup>+ </Tooltip>+ ) : savedConnection ? (<Button size="sm" variant="outline" disabled>{savedConnection.buttonLabel}</Button>diff --git a/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.test.ts b/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.test.tsindex 654c2462a6f..aed7bd44598 100644--- a/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.test.ts+++ b/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.test.ts@@ -40,6 +40,7 @@ describe("saved cloud environment connection presentation", () => {it.each([["error", "Connection failed", "Connection failed. Reason: Access denied.", "error"],+ ["unsupported", "Client not supported", "Client not supported", "idle"],["offline", "Offline", "Offline", "idle"],["available", "Not connected", "Available", "idle"],] as const)(diff --git a/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.ts b/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.tsindex 119a3366ac6..1e2dff0c9d5 100644--- a/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.ts+++ b/apps/web/src/components/cloud/cloudEnvironmentConnectionPresentation.ts@@ -36,11 +36,16 @@ export function presentSavedCloudEnvironmentConnection(statusText: connectionStatusText(connection),tone: "connecting",};+ // Not a failure: the machine is fine, this build just cannot talk to it.case "unsupported":+ return {+ buttonLabel: "Client not supported",+ statusText: connectionStatusText(connection),+ tone: "idle",+ };case "error":return {- buttonLabel:- connection.phase === "unsupported" ? "Client not supported" : "Connection failed",+ buttonLabel: "Connection failed",statusText: connectionStatusText(connection),tone: "error",};diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsxindex 49f312f3ddb..208efd61ed6 100644--- a/apps/web/src/components/settings/ConnectionsSettings.tsx+++ b/apps/web/src/components/settings/ConnectionsSettings.tsx@@ -161,6 +161,7 @@ import {type EnvironmentPresentation,useEnvironments,usePrimaryEnvironment,+ useRelayEnvironmentDiscovery,} from "~/state/environments";import { requestConfirmDialog } from "~/confirmDialog";import { useAtomCommand } from "../../state/use-atom-command";@@ -1457,8 +1458,9 @@ function savedBackendStatus(environment: EnvironmentPresentation): {text: connection.error ? `Reconnecting: ${connection.error}` : "Reconnecting",tone: "error",};+ // Not a failure: the machine is fine, this build just cannot talk to it.case "unsupported":- return { text: "Client not supported", tone: "error" };+ return { text: "Client not supported", tone: "muted" };case "error":return {text: connection.error ? `Connection failed: ${connection.error}` : "Connection failed",@@ -1519,6 +1521,17 @@ function SavedBackendListRow({serverUpdateState.status === "running" && serverUpdateState.stage === "resuming";const status = savedBackendStatus(environment);const serverVersion = environment.serverConfig?.environment.serverVersion ?? null;+ // A saved T3 Connect machine this device has never reached (unsupported,+ // or not yet connected) still has a descriptor from relay discovery, so+ // it can wear its detected glyph instead of the generic server.+ const relayDiscovery = useRelayEnvironmentDiscovery();+ const discoveredDescriptor = Option.getOrNull(+ relayDiscovery.environments.get(environmentId)?.status ?? Option.none(),+ )?.descriptor;+ const machineKind = resolveEnvironmentMachineKind(+ environment.serverConfig ??+ (discoveredDescriptor === undefined ? null : { environment: discoveredDescriptor }),+ );const subtitleText = [environmentTransportLabel(environment),resumingServerUpdate ? "Restarting" : status.text,@@ -1537,7 +1550,7 @@ function SavedBackendListRow({return (<EnvironmentRow- kind={resolveEnvironmentMachineKind(environment.serverConfig)}+ kind={machineKind}label={environment.label}dimmed={!enabled}subtitle={@@ -1558,7 +1571,11 @@ function SavedBackendListRow({{subtitleText}</TooltipTrigger><TooltipPopup side="top" className="max-w-80 whitespace-pre-wrap leading-tight">- {enabled || unsupported ? connectionStatusText(environment.connection) : "Switched off"}+ {unsupported && environment.connection.error+ ? environment.connection.error+ : enabled+ ? connectionStatusText(environment.connection)+ : "Switched off"}{versionMismatch? `\nUpdate available: ${versionMismatch.serverVersion} → ${versionMismatch.clientVersion}`: ""}diff --git a/packages/contracts/src/server.test.ts b/packages/contracts/src/server.test.tsindex 00bb5daa5b8..0a7e342ab75 100644--- a/packages/contracts/src/server.test.ts+++ b/packages/contracts/src/server.test.ts@@ -207,6 +207,12 @@ describe("resolveEnvironmentMachineKind", () => {).toBe("mac-mini");});+ it("uses detection from a bare descriptor before connecting", () => {+ expect(resolveEnvironmentMachineKind({ environment: descriptor({ machine: "laptop" }) })).toBe(+ "laptop",+ );+ });+it("falls back to a server for older servers and before connect", () => {expect(resolveEnvironmentMachineKind({diff --git a/packages/contracts/src/server.ts b/packages/contracts/src/server.tsindex c2fc8524ece..951ebddd50d 100644--- a/packages/contracts/src/server.ts+++ b/packages/contracts/src/server.ts@@ -598,14 +598,19 @@ export type ServerConfig = typeof ServerConfig.Type;/*** The machine an environment should be drawn as: the user's pick, else what- * the server detected, else a generic server. A null config (not connected- * yet, or an older server) resolves to the same generic so rows never- * flicker between glyphs.+ * the server detected, else a generic server. Settings only exist once+ * connected; a descriptor alone (relay discovery, before any connection)+ * still yields the detected kind. A null config (nothing known yet, or an+ * older server) resolves to the same generic so rows never flicker between+ * glyphs.*/export function resolveEnvironmentMachineKind(- config: Pick<ServerConfig, "environment" | "settings"> | null,+ config: {+ readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;+ readonly settings?: Pick<ServerSettings, "environmentIcon">;+ } | null,): EnvironmentMachineKind {- return config?.settings.environmentIcon ?? config?.environment.platform.machine ?? "server";+ return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";}const ServerUpsertKeybindingReplaceTarget = Schema.Struct({