Skip to content

Commit 928d638

Browse files
rodrigoB-CBclaude
andcommitted
fix(connect): the remove dialog says whether the environment is still on the account
The previous commit made the remove-from-device text hedge ("if it's still registered there"), which reads worse in the common case where it is. The app already has the relay's list, so the dialog now says the right thing: - registered: the original text and the account-page action - no longer listed: "It's no longer on your T3 Connect account.", without the deregister advice - list not loaded (signed out, loading, failed): neutral text Relay discovery gains a `listed` flag, true only once the current account's list has loaded, so a missing environment is distinguishable from one not listed yet; `relayEnvironmentRegistration` reads it. Deregistering on the T3 Connect account page now also refreshes discovery, so removing the saved copy right after deregistering shows the updated state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7498136 commit 928d638

9 files changed

Lines changed: 165 additions & 31 deletions

File tree

‎apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SymbolView } from "../../components/ui/AppSymbol";
1414
import * as Dialog from "../../components/ui/Dialog";
1515
import { Menu } from "../../components/ui/Menu";
1616
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
17+
import { relayEnvironmentDiscovery } from "../../state/relay";
1718
import { useAtomCommand } from "../../state/use-atom-command";
1819
import {
1920
deregisterManagedRelayEnvironmentCommand,
@@ -46,6 +47,9 @@ export function T3ConnectProfilePage() {
4647
const deregisterEnvironment = useAtomCommand(deregisterManagedRelayEnvironmentCommand, {
4748
reportFailure: false,
4849
});
50+
const refreshRelayEnvironments = useAtomCommand(relayEnvironmentDiscovery.refresh, {
51+
reportFailure: false,
52+
});
4953
const [deregisteringEnvironmentId, setDeregisteringEnvironmentId] =
5054
useState<EnvironmentId | null>(null);
5155
const mutationPendingRef = useRef(false);
@@ -76,6 +80,7 @@ export function T3ConnectProfilePage() {
7680
return { accountId, linkedAtById };
7781
});
7882
environmentsState.refresh();
83+
void refreshRelayEnvironments();
7984
return;
8085
}
8186
if (isAtomCommandInterrupted(result)) return;

‎apps/mobile/src/state/use-remote-environment-registry.ts‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Dialog from "../components/ui/Dialog";
22
import { useAtomValue } from "@effect/atom-react";
33
import { useNavigation } from "@react-navigation/native";
4+
import { Discovery } from "@t3tools/client-runtime/relay";
45
import type { EnvironmentId } from "@t3tools/contracts";
56
import * as Cause from "effect/Cause";
67
import { AsyncResult, Atom } from "effect/reactivity";
@@ -16,6 +17,15 @@ import { environmentSession } from "./session";
1617
import { environmentCatalog } from "../connection/catalog";
1718
import { createRemoteEnvironmentProjectionAtoms } from "./remote-environment-projections";
1819
import { serverEnvironment } from "./server";
20+
import { relayEnvironmentDiscovery } from "./relay";
21+
22+
const RELAY_REMOVAL_ACCOUNT_NOTE: Record<Discovery.RelayEnvironmentRegistration, string> = {
23+
registered:
24+
"It stays on your T3 Connect account and keeps its host space. Deregister it under T3 Account → T3 Connect to free it.",
25+
unregistered: "It's no longer on your T3 Connect account.",
26+
unknown:
27+
"This doesn't change your T3 Connect account. To deregister it there, use T3 Account → T3 Connect.",
28+
};
1929

2030
const connectionPairingUrlAtom = Atom.make("").pipe(
2131
Atom.keepAlive,
@@ -169,17 +179,20 @@ export function useRemoteConnections() {
169179
},
170180
} as const;
171181
if (environment.isRelayManaged) {
182+
const registration = Discovery.relayEnvironmentRegistration(
183+
appAtomRegistry.get(relayEnvironmentDiscovery.stateValueAtom),
184+
environmentId,
185+
);
186+
const openAccount = {
187+
text: "Open T3 Account",
188+
onPress: () => navigation.navigate("SettingsSheet", { screen: "SettingsAuth" }),
189+
};
172190
Dialog.alert(
173191
"Remove from this device?",
174-
`Forget ${environment.environmentLabel} and its cached threads on this device.\n\nYour T3 Connect account doesn't change. If it's still registered there, deregister it under T3 Account → T3 Connect to free its host space.`,
175-
[
176-
{ text: "Cancel", style: "cancel" },
177-
{
178-
text: "Open T3 Account",
179-
onPress: () => navigation.navigate("SettingsSheet", { screen: "SettingsAuth" }),
180-
},
181-
remove,
182-
],
192+
`Forget ${environment.environmentLabel} and its cached threads on this device.\n\n${RELAY_REMOVAL_ACCOUNT_NOTE[registration]}`,
193+
registration === "unregistered"
194+
? [{ text: "Cancel", style: "cancel" }, remove]
195+
: [{ text: "Cancel", style: "cancel" }, openAccount, remove],
183196
);
184197
return;
185198
}

‎apps/web/src/components/clerk/RemoveT3ConnectEnvironmentDialog.tsx‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Discovery } from "@t3tools/client-runtime/relay";
12
import { useState } from "react";
23

34
import {
@@ -14,17 +15,36 @@ import { useT3ConnectAccountPage } from "./T3ConnectAccountPages";
1415

1516
export function RemoveT3ConnectEnvironmentDialog({
1617
environmentLabel,
18+
registration,
1719
onCancel,
1820
onConfirm,
1921
}: {
2022
readonly environmentLabel: string | null;
23+
readonly registration: Discovery.RelayEnvironmentRegistration;
2124
readonly onCancel: () => void;
2225
readonly onConfirm: () => void;
2326
}) {
2427
const accountPage = useT3ConnectAccountPage();
25-
const [shownLabel, setShownLabel] = useState(environmentLabel);
26-
if (environmentLabel !== null && environmentLabel !== shownLabel) setShownLabel(environmentLabel);
28+
const [shown, setShown] = useState({ label: environmentLabel, registration });
29+
if (
30+
environmentLabel !== null &&
31+
(environmentLabel !== shown.label || registration !== shown.registration)
32+
) {
33+
setShown({ label: environmentLabel, registration });
34+
}
2735
const openAccountPage = accountPage.open;
36+
const accountPageLink = openAccountPage ? (
37+
<InlineButton
38+
onClick={() => {
39+
onCancel();
40+
openAccountPage();
41+
}}
42+
>
43+
T3 Connect settings
44+
</InlineButton>
45+
) : (
46+
"T3 Connect settings"
47+
);
2848

2949
return (
3050
<>
@@ -36,26 +56,24 @@ export function RemoveT3ConnectEnvironmentDialog({
3656
>
3757
<AlertDialogPopup>
3858
<AlertDialogHeader>
39-
<AlertDialogTitle>Remove {shownLabel} from this device?</AlertDialogTitle>
59+
<AlertDialogTitle>Remove {shown.label} from this device?</AlertDialogTitle>
4060
<AlertDialogDescription>
4161
This forgets its pairing, credentials, and cached threads here.
4262
</AlertDialogDescription>
4363
<AlertDialogDescription>
44-
Your T3 Connect account doesn't change. If it's still registered there, deregister it
45-
in{" "}
46-
{openAccountPage ? (
47-
<InlineButton
48-
onClick={() => {
49-
onCancel();
50-
openAccountPage();
51-
}}
52-
>
53-
T3 Connect settings
54-
</InlineButton>
64+
{shown.registration === "registered" ? (
65+
<>
66+
It stays on your T3 Connect account and keeps its host space. Deregister it in{" "}
67+
{accountPageLink} to free it.
68+
</>
69+
) : shown.registration === "unregistered" ? (
70+
"It's no longer on your T3 Connect account."
5571
) : (
56-
"T3 Connect settings"
57-
)}{" "}
58-
to free its host space.
72+
<>
73+
This doesn't change your T3 Connect account. To deregister it there, use{" "}
74+
{accountPageLink}.
75+
</>
76+
)}
5977
</AlertDialogDescription>
6078
</AlertDialogHeader>
6179
<AlertDialogFooter>

‎apps/web/src/components/clerk/T3ConnectUserProfilePage.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
deregisterManagedRelayEnvironmentCommand,
1313
useManagedRelayEnvironments,
1414
} from "../../cloud/managedRelayState";
15+
import { relayEnvironmentDiscovery } from "../../state/relay";
1516
import { useAtomCommand } from "../../state/use-atom-command";
1617
import { Button } from "../ui/button";
1718
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
@@ -115,6 +116,9 @@ export function T3ConnectUserProfilePage() {
115116
const deregisterEnvironment = useAtomCommand(deregisterManagedRelayEnvironmentCommand, {
116117
reportFailure: false,
117118
});
119+
const refreshRelayEnvironments = useAtomCommand(relayEnvironmentDiscovery.refresh, {
120+
reportFailure: false,
121+
});
118122
const [deregisteringEnvironmentId, setDeregisteringEnvironmentId] =
119123
useState<EnvironmentId | null>(null);
120124
const [confirmingEnvironmentId, setConfirmingEnvironmentId] = useState<EnvironmentId | null>(
@@ -147,6 +151,7 @@ export function T3ConnectUserProfilePage() {
147151
return { accountId, linkedAtById };
148152
});
149153
environmentsState.refresh();
154+
void refreshRelayEnvironments();
150155
toastManager.add({
151156
type: "success",
152157
title: "Server deregistered",

‎apps/web/src/components/cloud/CloudEnvironmentConnectList.browser.test.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,29 @@ beforeEach(() => {
121121
discovery.listeners.clear();
122122
discovery.state = {
123123
environments: new Map(),
124+
listed: false,
124125
refreshing: false,
125126
offline: false,
126127
error: Option.none(),
127128
};
128129
discovery.listEnvironments.mockReset().mockResolvedValue(new Map());
129130
discovery.register.mockReset().mockResolvedValue(AsyncResult.success(undefined));
130131
discovery.refresh.mockReset().mockImplementation(async () => {
131-
publish({ environments: new Map(), refreshing: true, offline: false, error: Option.none() });
132+
publish({
133+
environments: new Map(),
134+
listed: false,
135+
refreshing: true,
136+
offline: false,
137+
error: Option.none(),
138+
});
132139
const environments = await discovery.listEnvironments();
133-
publish({ environments, refreshing: false, offline: false, error: Option.none() });
140+
publish({
141+
environments,
142+
listed: true,
143+
refreshing: false,
144+
offline: false,
145+
error: Option.none(),
146+
});
134147
return AsyncResult.success(undefined);
135148
});
136149
});
@@ -166,6 +179,7 @@ describe("cloud environment offline reasons", () => {
166179
await act(async () => {
167180
publish({
168181
environments: new Map([[newMachineId, offlineEntry("tunnel_released")]]),
182+
listed: true,
169183
refreshing: false,
170184
offline: false,
171185
error: Option.none(),

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
connectionStatusText,
5151
environmentMcpUrl,
5252
} from "@t3tools/client-runtime/connection";
53+
import { Discovery } from "@t3tools/client-runtime/relay";
5354
import {
5455
isAtomCommandInterrupted,
5556
settlePromise,
@@ -3934,6 +3935,14 @@ export function ConnectionsSettings() {
39343935
{hasCloudPublicConfig() ? (
39353936
<RemoveT3ConnectEnvironmentDialog
39363937
environmentLabel={pendingT3ConnectRemoval?.label ?? null}
3938+
registration={
3939+
pendingT3ConnectRemoval
3940+
? Discovery.relayEnvironmentRegistration(
3941+
relayDiscoveryState,
3942+
pendingT3ConnectRemoval.environmentId,
3943+
)
3944+
: "unknown"
3945+
}
39373946
onCancel={() => setPendingT3ConnectRemoval(null)}
39383947
onConfirm={() => {
39393948
if (!pendingT3ConnectRemoval) return;

‎docs/user/remote-access.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ shows that it was removed from T3 Connect. To link it again, turn on
307307
command-line host that released its tunnel when it last stopped may link itself
308308
again on its next start; run `t3 connect unlink` on that host to keep it off.
309309
Removing an environment from a device's connection settings only forgets it on
310-
that device and doesn't change your T3 Connect account. A device keeps an
311-
environment that was deregistered elsewhere until you remove it there.
310+
that device and doesn't change your T3 Connect account. A device keeps a saved
311+
environment after it's deregistered until you remove it from that device.
312312

313313
When idle tunnel cleanup is enabled, T3 Connect removes a linked environment's
314314
tunnel after it stays offline for several minutes. The environment stays linked

‎packages/client-runtime/src/relay/discovery.test.ts‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,38 @@ describe("RelayEnvironmentDiscovery", () => {
225225
}),
226226
);
227227

228+
it.effect("reports an environment as unregistered only once the relay list has loaded", () =>
229+
Effect.gen(function* () {
230+
const harness = yield* makeHarness();
231+
yield* Effect.gen(function* () {
232+
const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery;
233+
const listed = environments[0]!.environmentId;
234+
const deregistered = "deregistered-environment";
235+
const before = yield* SubscriptionRef.get(discovery.state);
236+
expect(RelayEnvironmentDiscovery.relayEnvironmentRegistration(before, deregistered)).toBe(
237+
"unknown",
238+
);
239+
240+
const requests = yield* Ref.get(harness.statusRequests);
241+
for (const environment of environments) {
242+
yield* Deferred.succeed(
243+
requests.get(environment.environmentId)!,
244+
status(environment, "online"),
245+
);
246+
}
247+
yield* discovery.refresh;
248+
249+
const after = yield* SubscriptionRef.get(discovery.state);
250+
expect(RelayEnvironmentDiscovery.relayEnvironmentRegistration(after, listed)).toBe(
251+
"registered",
252+
);
253+
expect(RelayEnvironmentDiscovery.relayEnvironmentRegistration(after, deregistered)).toBe(
254+
"unregistered",
255+
);
256+
}).pipe(Effect.provide(harness.layer));
257+
}),
258+
);
259+
228260
it.effect(
229261
"preserves discovered rows while offline and refreshes after connectivity returns",
230262
() =>
@@ -344,6 +376,12 @@ describe("RelayEnvironmentDiscovery", () => {
344376
const failed = yield* SubscriptionRef.get(discovery.state);
345377
expect(failed.environments.size).toBe(0);
346378
expect(Option.isSome(failed.error)).toBe(true);
379+
expect(
380+
RelayEnvironmentDiscovery.relayEnvironmentRegistration(
381+
failed,
382+
environments[0]!.environmentId,
383+
),
384+
).toBe("unknown");
347385
}).pipe(Effect.provide(harness.layer));
348386
}),
349387
);
@@ -391,6 +429,12 @@ describe("RelayEnvironmentDiscovery", () => {
391429
expect(state.environments.size).toBe(0);
392430
expect(state.refreshing).toBe(false);
393431
expect(Option.isNone(state.error)).toBe(true);
432+
expect(
433+
RelayEnvironmentDiscovery.relayEnvironmentRegistration(
434+
state,
435+
environments[0]!.environmentId,
436+
),
437+
).toBe("unknown");
394438
}).pipe(Effect.provide(harness.layer));
395439
}),
396440
);
@@ -423,7 +467,14 @@ describe("RelayEnvironmentDiscovery", () => {
423467
yield* Fiber.join(refreshFiber);
424468
yield* Effect.yieldNow;
425469

426-
expect((yield* SubscriptionRef.get(discovery.state)).environments.size).toBe(0);
470+
const signedOut = yield* SubscriptionRef.get(discovery.state);
471+
expect(signedOut.environments.size).toBe(0);
472+
expect(
473+
RelayEnvironmentDiscovery.relayEnvironmentRegistration(
474+
signedOut,
475+
environments[0]!.environmentId,
476+
),
477+
).toBe("unknown");
427478
}).pipe(Effect.provide(harness.layer), Effect.scoped);
428479
}),
429480
);

‎packages/client-runtime/src/relay/discovery.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export interface RelayDiscoveredEnvironment {
3434

3535
export interface RelayEnvironmentDiscoveryState {
3636
readonly environments: ReadonlyMap<string, RelayDiscoveredEnvironment>;
37+
/**
38+
* The relay's list for the current account has loaded, so an environment
39+
* missing from `environments` is no longer registered rather than not yet
40+
* listed. Signed-out, failed, and reset states are not listed.
41+
*/
42+
readonly listed: boolean;
3743
readonly refreshing: boolean;
3844
readonly offline: boolean;
3945
readonly error: Option.Option<ConnectionAttemptError>;
@@ -49,11 +55,22 @@ export class RelayEnvironmentDiscovery extends Context.Service<
4955

5056
export const EMPTY_RELAY_ENVIRONMENT_DISCOVERY_STATE: RelayEnvironmentDiscoveryState = {
5157
environments: new Map(),
58+
listed: false,
5259
refreshing: false,
5360
offline: false,
5461
error: Option.none(),
5562
};
5663

64+
export type RelayEnvironmentRegistration = "registered" | "unregistered" | "unknown";
65+
66+
export function relayEnvironmentRegistration(
67+
state: RelayEnvironmentDiscoveryState,
68+
environmentId: string,
69+
): RelayEnvironmentRegistration {
70+
if (state.environments.has(environmentId)) return "registered";
71+
return state.listed ? "unregistered" : "unknown";
72+
}
73+
5774
function validateStatus(
5875
environment: RelayClientEnvironmentRecord,
5976
status: RelayEnvironmentStatusResponse,
@@ -218,6 +235,7 @@ export const make = Effect.fn("RelayEnvironmentDiscovery.make")(function* () {
218235
yield* Ref.set(refreshGeneration, generation);
219236
yield* SubscriptionRef.set(state, {
220237
environments: new Map(),
238+
listed: false,
221239
refreshing: true,
222240
offline: false,
223241
error: Option.none(),
@@ -276,6 +294,7 @@ export const make = Effect.fn("RelayEnvironmentDiscovery.make")(function* () {
276294
yield* SubscriptionRef.update(state, (current) => ({
277295
...current,
278296
environments: next,
297+
listed: true,
279298
}));
280299

281300
yield* Effect.forEach(

0 commit comments

Comments
 (0)