The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
fix(web): keep reopened pairing link dialogs open on completion (#39579)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 20, 2026 at 09:27 UTC
d15123668e3a16d1e460c4d6d1d7ed77cd54ebc3
2 files changed
+66
-15
apps/web/src/components/settings/AuthorizedClientsSettings.tsx
+18
-15
@@ -3,7 +3,7 @@ import { m as resolveMessage } from "~/i18n/messages";
3
import { managedCapabilityDenial } from "@t3tools/client-runtime/contract-labels";
4
import { AUTH_SCOPE_OPTIONS as PAIRING_SCOPE_OPTIONS } from "@t3tools/shared/authScopeOptions";
5
import { PlugIcon, PlusIcon, QrCodeIcon } from "lucide-react";
6
-import { type ReactNode, memo, useId, useState } from "react";
6
+import { type ReactNode, memo, useId, useRef, useState } from "react";
7
import { T, useGT, useMessages } from "gt-react";
8
import {
9
AuthAccessWriteScope,
@@ -614,6 +614,7 @@ export const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHead
614
reportFailure: false,
615
});
616
const [dialogOpen, setDialogOpen] = useState(false);
617
+ const pairingDialogSessionRef = useRef(0);
618
const [pairingLabel, setPairingLabel] = useState("");
619
const [pairingScopes, setPairingScopes] = useState<ReadonlyArray<AuthGrantScope>>([
620
...AuthStandardClientScopes,
@@ -623,6 +624,17 @@ export const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHead
624
const relayAdminSelected = selectedScopes.includes(AuthRelayConfigureScope);
625
const [isCreatingPairingLink, setIsCreatingPairingLink] = useState(false);
626
627
+ const handlePairingDialogOpenChange = (open: boolean) => {
628
+ setDialogOpen(open);
629
+ if (!open) {
630
+ pairingDialogSessionRef.current += 1;
631
+ setPairingLabel("");
632
+ setPairingScopes(
633
+ AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
634
+ );
635
+ }
636
+ };
637
+
638
const handleCreatePairingLink = async () => {
639
if (
640
selectedScopes.length === 0 ||
@@ -630,6 +642,7 @@ export const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHead
642
!selectedScopes.every((scope) => readEnvironmentScope(environmentId, scope))
643
)
644
return;
645
+ const dialogSession = pairingDialogSessionRef.current;
646
setIsCreatingPairingLink(true);
647
const trimmedLabel = pairingLabel.trim();
648
const result = await createPairingCredential({
@@ -638,11 +651,9 @@ export const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHead
651
});
652
if (result._tag === "Success") {
653
onPairingLinkCreated(result.value);
641
- setPairingLabel("");
642
- setPairingScopes(
643
- AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
644
- );
645
- setDialogOpen(false);
654
+ if (dialogSession === pairingDialogSessionRef.current) {
655
+ handlePairingDialogOpenChange(false);
656
+ }
657
} else if (!isAtomCommandInterrupted(result)) {
658
const error = squashAtomCommandFailure(result);
659
const message =
@@ -688,15 +699,7 @@ export const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHead
699
) : null}
700
<Dialog
701
open={dialogOpen && pairingDenial === undefined}
691
- onOpenChange={(open) => {
692
- setDialogOpen(open);
693
- if (!open) {
694
- setPairingLabel("");
695
- setPairingScopes(
696
- AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
697
- );
698
- }
699
- }}
702
+ onOpenChange={handlePairingDialogOpenChange}
703
>
704
{pairingDenial === undefined ? (
705
<DialogTrigger
scripts/scenarios/pairing-completion-keeps-reopened-dialog.e2e.ts
new
+48
@@ -0,0 +1,48 @@
1
+import { expect } from "e2e";
2
+
3
+import { test, WEB } from "./t3.ts";
4
+
5
+test(
6
+ "Finishing a pairing link leaves a reopened Create link dialog open",
7
+ WEB,
8
+ async ({ t3, app, browser, screen }) => {
9
+ await t3.project("demo");
10
+ const pairingToken = "**/api/auth/pairing-token";
11
+ const requested = Promise.withResolvers<void>();
12
+ const release = Promise.withResolvers<void>();
13
+ await browser.route(pairingToken, async (route) => {
14
+ if (route.request.method !== "POST") return route.fallback();
15
+ requested.resolve();
16
+ await release.promise;
17
+ await route.continue();
18
+ });
19
+
20
+ await t3.open("/settings/access");
21
+ const authorizedClients = browser.locator("#authorized-clients");
22
+ const open = authorizedClients.getByRole("button", "Create link", { exact: true });
23
+ const dialog = screen.getByRole("dialog", "Create pairing link", { exact: true });
24
+ // A closing popup keeps its role until its exit animation ends; only an open one has data-open.
25
+ const openDialog = browser
26
+ .locator('[data-slot="dialog-popup"][data-open]')
27
+ .getByRole("heading", "Create pairing link", { exact: true });
28
+ const label = "Waiting tablet";
29
+ try {
30
+ await open.tap();
31
+ await dialog.getByPlaceholder("e.g. Living room iPad").fill(label);
32
+ await dialog.getByRole("button", "Create link", { exact: true }).tap();
33
+ await requested.promise;
34
+ await browser.keyboard.press("Escape");
35
+ await dialog.waitFor({ state: "hidden" });
36
+ await open.tap();
37
+ await openDialog.waitFor();
38
+
39
+ release.resolve();
40
+ await authorizedClients.getByText(label, { exact: true }).waitFor();
41
+ await app.screenshot("after-first-link-finishes");
42
+ await expect(openDialog).toBeVisible();
43
+ } finally {
44
+ release.resolve();
45
+ await browser.unroute(pairingToken);
46
+ }
47
+ },
48
+);