Skip to content
TypeScript

fix(clients): hold the discovered machine icon across relay refreshes (#12030)

Julius Marminge6ee03240bccd
diff --git a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx
index b1748b1938c..dbb1dca068d 100644
--- a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx
+++ b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx
@@ -235,6 +235,12 @@ function ConnectedCloudEnvironmentRow(props: {
);
const unsupported = props.environment.connectionState === "unsupported";
const enabled = props.environment.isEnabled && !unsupported;
+ // Discovery empties its map on every refresh; hold the last descriptor seen
+ // so the glyph does not blink back to the generic one each time.
+ const [lastDescriptor, setLastDescriptor] = useState(props.descriptor);
+ if (props.descriptor !== undefined && props.descriptor !== lastDescriptor) {
+ setLastDescriptor(props.descriptor);
+ }
return (
<Pressable
accessibilityHint="Long press to remove from this device"
@@ -248,8 +254,7 @@ function ConnectedCloudEnvironmentRow(props: {
errorExpanded={props.errorExpanded}
label={props.environment.environmentLabel}
machine={resolveEnvironmentMachineKind(
- serverConfig ??
- (props.descriptor === undefined ? null : { environment: props.descriptor }),
+ serverConfig ?? (lastDescriptor === undefined ? null : { environment: lastDescriptor }),
)}
onValueChange={props.onSetEnabled}
onToggleError={props.onToggleError}
diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx
index 208efd61ed6..324361d7fb6 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.tsx
+++ b/apps/web/src/components/settings/ConnectionsSettings.tsx
@@ -1523,14 +1523,20 @@ function SavedBackendListRow({
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.
+ // it can wear its detected glyph instead of the generic server. Discovery
+ // empties its map on every refresh, so hold the last descriptor seen or
+ // the glyph would blink back to the generic one each time.
const relayDiscovery = useRelayEnvironmentDiscovery();
const discoveredDescriptor = Option.getOrNull(
relayDiscovery.environments.get(environmentId)?.status ?? Option.none(),
)?.descriptor;
+ const [lastDescriptor, setLastDescriptor] = useState(discoveredDescriptor);
+ if (discoveredDescriptor !== undefined && discoveredDescriptor !== lastDescriptor) {
+ setLastDescriptor(discoveredDescriptor);
+ }
const machineKind = resolveEnvironmentMachineKind(
environment.serverConfig ??
- (discoveredDescriptor === undefined ? null : { environment: discoveredDescriptor }),
+ (lastDescriptor === undefined ? null : { environment: lastDescriptor }),
);
const subtitleText = [
environmentTransportLabel(environment),
@@ -1560,10 +1566,7 @@ function SavedBackendListRow({
<span
className={cn(
"block truncate",
- (enabled || unsupported) &&
- status.tone === "error" &&
- !resumingServerUpdate &&
- "text-destructive",
+ enabled && status.tone === "error" && !resumingServerUpdate && "text-destructive",
)}
/>
}
@@ -1571,8 +1574,8 @@ function SavedBackendListRow({
{subtitleText}
</TooltipTrigger>
<TooltipPopup side="top" className="max-w-80 whitespace-pre-wrap leading-tight">
- {unsupported && environment.connection.error
- ? environment.connection.error
+ {unsupported
+ ? (environment.connection.error ?? connectionStatusText(environment.connection))
: enabled
? connectionStatusText(environment.connection)
: "Switched off"}