@devries-cameron20 / t3code Mirror · read-only / commits / ecb973a7df
Fork 0

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 23, 06:45 UTC

perf(web): the Connect onboarding dialog compiles with the React Compiler (#20622)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 22:00 UTC ecb973a7df86421adce88120d6de41854705d620
1 file changed +37 -53
apps/web/src/components/cloud/ConnectOnboardingDialog.tsx
+37 -53
@@ -2,7 +2,7 @@ import { useAuth } from "@clerk/react";
2 import { useAtomValue } from "@effect/atom-react";
3 import { AuthRelayReadScope, AuthRelayWriteScope, type AuthSessionState } from "@t3tools/contracts";
4 import { AsyncResult, Atom } from "effect/reactivity";
5 -import { useEffect, useRef, useState } from "react";
5 +import { useState } from "react";
6
7 import {
8 CONNECT_ONBOARDING_OPT_OUT_STORAGE_KEY,
@@ -72,30 +72,36 @@ function ConfiguredConnectOnboardingDialog() {
72 const [publishAgentActivity, setPublishAgentActivity] = useState(true);
73 const [dontShowAgain, setDontShowAgain] = useState(false);
74 const [isApplying, setIsApplying] = useState(false);
75 - const prefilledFromLinkStateRef = useRef(false);
76 - const observedAccountRef = useRef<string | null | undefined>(undefined);
75 + const [prefilledFromLinkState, setPrefilledFromLinkState] = useState(false);
76 + // undefined until auth first settles, so the account already signed in at load
77 + // never reads as a fresh sign-in.
78 + const [observedAccount, setObservedAccount] = useState<string | null | undefined>(undefined);
79
78 - useEffect(() => {
79 - if (step === "publish" && sessionScopesKnown && !showPublishStep && !isApplying) {
80 - setStep("devices");
81 - }
82 - }, [isApplying, sessionScopesKnown, showPublishStep, step]);
80 + if (step === "publish" && sessionScopesKnown && !showPublishStep && !isApplying) {
81 + setStep("devices");
82 + }
83
84 const optOutAccounts = optOutState.optOutAccounts;
85
86 - useEffect(() => {
87 - if (!isLoaded) return;
88 - // A loaded-but-incomplete snapshot (signed in, user id not yet populated)
89 - // must not be recorded as signed-out — the next render would then look
90 - // like a fresh sign-in on a cold load.
91 - if (isSignedIn && !userId) return;
92 - const previousAccount = observedAccountRef.current;
86 + // A loaded-but-incomplete snapshot (signed in, user id not yet populated)
87 + // must not be recorded as signed-out — the next render would then look
88 + // like a fresh sign-in on a cold load.
89 + if (isLoaded && !(isSignedIn && !userId)) {
90 const nextAccount = isSignedIn && userId ? userId : null;
94 - observedAccountRef.current = nextAccount;
95 - if (previousAccount !== undefined && previousAccount !== nextAccount && nextAccount !== null) {
96 - setRequestedAccount(nextAccount);
91 + if (nextAccount !== observedAccount) {
92 + setObservedAccount(nextAccount);
93 + if (observedAccount !== undefined && nextAccount !== null) {
94 + setRequestedAccount(nextAccount);
95 + }
96 }
98 - }, [isLoaded, isSignedIn, userId]);
97 + }
98 +
99 + if (openForAccount !== null && (!isSignedIn || userId !== openForAccount)) {
100 + setOpenForAccount(null);
101 + }
102 + if (requestedAccount !== null && (!isSignedIn || userId !== requestedAccount)) {
103 + setRequestedAccount(null);
104 + }
105
106 // A manageable session implies a primary environment, so when the scopes
107 // allow publishing, wait for the connection target too — otherwise the
@@ -103,45 +109,23 @@ function ConfiguredConnectOnboardingDialog() {
109 // becomes available and freeze there.
110 const publishStepDecided = !canManageRelay || controller.linkState.target !== null;
111
106 - useEffect(() => {
107 - if (requestedAccount === null || openForAccount !== null) return;
112 + if (requestedAccount !== null && openForAccount === null) {
113 if (optOutAccounts.includes(requestedAccount)) {
114 setRequestedAccount(null);
110 - return;
111 - }
112 - if (!sessionScopesKnown || !publishStepDecided) return;
113 - setRequestedAccount(null);
114 - prefilledFromLinkStateRef.current = false;
115 - setExposeEnvironment(true);
116 - setPublishAgentActivity(true);
117 - setDontShowAgain(false);
118 - setStep(canManageRelay && controller.linkState.target !== null ? "publish" : "devices");
119 - setOpenForAccount(requestedAccount);
120 - }, [
121 - canManageRelay,
122 - controller.linkState.target,
123 - openForAccount,
124 - optOutAccounts,
125 - publishStepDecided,
126 - requestedAccount,
127 - sessionScopesKnown,
128 - ]);
129 -
130 - useEffect(() => {
131 - if (openForAccount !== null && (!isSignedIn || userId !== openForAccount)) {
132 - setOpenForAccount(null);
133 - }
134 - if (requestedAccount !== null && (!isSignedIn || userId !== requestedAccount)) {
115 + } else if (sessionScopesKnown && publishStepDecided) {
116 setRequestedAccount(null);
117 + setPrefilledFromLinkState(false);
118 + setExposeEnvironment(true);
119 + setPublishAgentActivity(true);
120 + setDontShowAgain(false);
121 + setStep(canManageRelay && controller.linkState.target !== null ? "publish" : "devices");
122 + setOpenForAccount(requestedAccount);
123 }
137 - }, [isSignedIn, openForAccount, requestedAccount, userId]);
124 + }
125
126 const linkStateData = controller.linkState.data;
140 - useEffect(() => {
141 - if (openForAccount === null || prefilledFromLinkStateRef.current || linkStateData === null) {
142 - return;
143 - }
144 - prefilledFromLinkStateRef.current = true;
127 + if (openForAccount !== null && !prefilledFromLinkState && linkStateData !== null) {
128 + setPrefilledFromLinkState(true);
129 if (
130 linkStateData.linked &&
131 linkStateData.linkRevoked !== true &&
@@ -150,7 +134,7 @@ function ConfiguredConnectOnboardingDialog() {
134 setExposeEnvironment(linkStateData.managedTunnelActive ?? linkStateData.linked);
135 setPublishAgentActivity(linkStateData.publishAgentActivity);
136 }
153 - }, [linkStateData, openForAccount]);
137 + }
138
139 const complete = () => {
140 if (isApplying) return;