@devries-cameron20 / t3code Mirror · read-only / commits / f31850cd2a
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, 08:00 UTC

perf(web): provider update rows compile with the React Compiler (#20481)

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

Julius Marminge committed Oct 16, 2026 at 18:46 UTC f31850cd2aa972d5c22c58f4038dfc25a24bf619
2 files changed +114 -123
apps/web/reactCompiledFiles.ts
+1
@@ -56,4 +56,5 @@ export const REACT_COMPILED_FILES = [
56 "apps/web/src/components/ServerUpdateAction.tsx",
57 "apps/web/src/components/files/AttachmentFilePreview.tsx",
58 "apps/web/src/components/usage/UsagePage.tsx",
59 + "apps/web/src/components/ProviderUpdateEnvironmentRows.tsx",
60 ] as const;
apps/web/src/components/ProviderUpdateEnvironmentRows.tsx
+113 -123
@@ -1,5 +1,5 @@
1 import { CheckIcon } from "lucide-react";
2 -import { type ReactNode, useCallback, useMemo, useRef, useState } from "react";
2 +import { type ReactNode, useRef, useState } from "react";
3 import {
4 AuthProvidersManageScope,
5 type EnvironmentId,
@@ -7,6 +7,7 @@ import {
7 } from "@t3tools/contracts";
8 import {
9 isAtomCommandInterrupted,
10 + settlePromise,
11 squashAtomCommandFailure,
12 type AtomCommandResult,
13 } from "@t3tools/client-runtime/state/runtime";
@@ -160,12 +161,9 @@ export function ProviderUpdateEnvironmentRows({
161 const updateProvider = useAtomCommand(serverEnvironment.updateProvider, {
162 reportFailure: false,
163 });
163 - const groupByEnvironment = useMemo(
164 - () => new Map(groups.map((group) => [group.environmentId, group] as const)),
165 - [groups],
166 - );
164 + const groupByEnvironment = new Map(groups.map((group) => [group.environmentId, group] as const));
165
168 - const visibleAfterIsoRef = useRef<string>(new Date().toISOString());
166 + const [visibleAfterIso] = useState(() => new Date().toISOString());
167
168 // setPendingEnvironments is an async state update, and PENDING_EXPIRY_MS can
169 // clear the spinner while a request is still in flight, so a rapid
@@ -191,7 +189,7 @@ export function ProviderUpdateEnvironmentRows({
189 ReadonlyMap<EnvironmentId, ProviderUpdateToastView>
190 >(() => new Map());
191
194 - const clearPending = useCallback((environmentId: EnvironmentId) => {
192 + const clearPending = (environmentId: EnvironmentId) => {
193 setPendingEnvironments((previous) => {
194 if (!previous.has(environmentId)) {
195 return previous;
@@ -200,31 +198,81 @@ export function ProviderUpdateEnvironmentRows({
198 next.delete(environmentId);
199 return next;
200 });
203 - }, []);
201 + };
202 +
203 + const handleUpdate = async (environmentId: EnvironmentId) => {
204 + if (!readEnvironmentScope(environmentId, AuthProvidersManageScope)) return;
205 + const group = groupByEnvironment.get(environmentId);
206 + if (!group || group.candidates.length === 0) {
207 + return;
208 + }
209 + if (inFlightEnvironmentsRef.current.has(environmentId)) {
210 + return;
211 + }
212 + inFlightEnvironmentsRef.current.add(environmentId);
213 + const requestVersion = (requestVersionRef.current.get(environmentId) ?? 0) + 1;
214 + requestVersionRef.current.set(environmentId, requestVersion);
215 + const isCurrentRequest = () => requestVersionRef.current.get(environmentId) === requestVersion;
216 + onInteract?.();
217 + const providerCount = group.candidates.length;
218 + const targets = group.candidates.map((candidate) => ({
219 + driver: candidate.driver,
220 + instanceId: candidate.instanceId,
221 + }));
222 +
223 + setPendingEnvironments((previous) => new Set(previous).add(environmentId));
224 + setErrorByEnvironment((previous) => {
225 + if (!previous.has(environmentId)) {
226 + return previous;
227 + }
228 + const next = new Map(previous);
229 + next.delete(environmentId);
230 + return next;
231 + });
232 + setResultByEnvironment((previous) => {
233 + if (!previous.has(environmentId)) {
234 + return previous;
235 + }
236 + const next = new Map(previous);
237 + next.delete(environmentId);
238 + return next;
239 + });
240
205 - const handleUpdate = useCallback(
206 - async (environmentId: EnvironmentId) => {
207 - if (!readEnvironmentScope(environmentId, AuthProvidersManageScope)) return;
208 - const group = groupByEnvironment.get(environmentId);
209 - if (!group || group.candidates.length === 0) {
241 + const expiry = setTimeout(() => {
242 + if (!isCurrentRequest()) {
243 return;
244 }
212 - if (inFlightEnvironmentsRef.current.has(environmentId)) {
245 + inFlightEnvironmentsRef.current.delete(environmentId);
246 + clearPending(environmentId);
247 + setErrorByEnvironment((previous) =>
248 + new Map(previous).set(environmentId, "Update timed out — try again."),
249 + );
250 + }, PENDING_EXPIRY_MS);
251 + const settled = await settlePromise(async () => {
252 + const results = await Promise.all(
253 + targets.map(async (target): Promise<PromiseSettledResult<LocalProviderUpdateOutcome>> => {
254 + try {
255 + const result = await updateProvider({
256 + environmentId,
257 + input: { provider: target.driver, instanceId: target.instanceId },
258 + });
259 + return toProviderUpdateOutcome({
260 + environmentId,
261 + isPrimary: group.isPrimary,
262 + target,
263 + result,
264 + });
265 + } catch (error) {
266 + return {
267 + status: "rejected",
268 + reason: error instanceof Error ? error : new Error("Provider update failed."),
269 + };
270 + }
271 + }),
272 + );
273 + if (!isCurrentRequest()) {
274 return;
275 }
215 - inFlightEnvironmentsRef.current.add(environmentId);
216 - const requestVersion = (requestVersionRef.current.get(environmentId) ?? 0) + 1;
217 - requestVersionRef.current.set(environmentId, requestVersion);
218 - const isCurrentRequest = () =>
219 - requestVersionRef.current.get(environmentId) === requestVersion;
220 - onInteract?.();
221 - const providerCount = group.candidates.length;
222 - const targets = group.candidates.map((candidate) => ({
223 - driver: candidate.driver,
224 - instanceId: candidate.instanceId,
225 - }));
226 -
227 - setPendingEnvironments((previous) => new Set(previous).add(environmentId));
276 setErrorByEnvironment((previous) => {
277 if (!previous.has(environmentId)) {
278 return previous;
@@ -233,104 +281,46 @@ export function ProviderUpdateEnvironmentRows({
281 next.delete(environmentId);
282 return next;
283 });
236 - setResultByEnvironment((previous) => {
237 - if (!previous.has(environmentId)) {
238 - return previous;
239 - }
240 - const next = new Map(previous);
241 - next.delete(environmentId);
242 - return next;
243 - });
244 -
245 - const expiry = setTimeout(() => {
246 - if (!isCurrentRequest()) {
247 - return;
248 - }
249 - inFlightEnvironmentsRef.current.delete(environmentId);
250 - clearPending(environmentId);
284 + if (results.length === 0) {
285 setErrorByEnvironment((previous) =>
252 - new Map(previous).set(environmentId, "Update timed out — try again."),
253 - );
254 - }, PENDING_EXPIRY_MS);
255 - try {
256 - const results = await Promise.all(
257 - targets.map(async (target): Promise<PromiseSettledResult<LocalProviderUpdateOutcome>> => {
258 - try {
259 - const result = await updateProvider({
260 - environmentId,
261 - input: { provider: target.driver, instanceId: target.instanceId },
262 - });
263 - return toProviderUpdateOutcome({
264 - environmentId,
265 - isPrimary: group.isPrimary,
266 - target,
267 - result,
268 - });
269 - } catch (error) {
270 - return {
271 - status: "rejected",
272 - reason: error instanceof Error ? error : new Error("Provider update failed."),
273 - };
274 - }
275 - }),
286 + new Map(previous).set(
287 + environmentId,
288 + "This environment isn’t connected — try again once it reconnects.",
289 + ),
290 );
277 - if (!isCurrentRequest()) {
278 - return;
279 - }
280 - setErrorByEnvironment((previous) => {
281 - if (!previous.has(environmentId)) {
282 - return previous;
283 - }
284 - const next = new Map(previous);
285 - next.delete(environmentId);
286 - return next;
287 - });
288 - if (results.length === 0) {
289 - setErrorByEnvironment((previous) =>
290 - new Map(previous).set(
291 - environmentId,
292 - "This environment isn’t connected — try again once it reconnects.",
293 - ),
294 - );
295 - return;
296 - }
297 - const rejectedMessage = firstRejectedProviderUpdateMessage(results);
298 - if (rejectedMessage) {
299 - setErrorByEnvironment((previous) =>
300 - new Map(previous).set(environmentId, rejectedMessage),
301 - );
302 - return;
303 - }
304 - const view = getProviderUpdateProgressToastView({
305 - providers: collectProviderUpdateOutcomeSnapshots(results),
306 - providerCount,
307 - });
308 - // A stored view never re-polls, so persisting it would pin the row's
309 - // spinner forever once the pending flag expires. Drop it and let the
310 - // live per-environment provider state (pill) plus the pending expiry
311 - // drive the row, so it self-heals to whatever the backend actually did.
312 - if (isTerminalProviderUpdatePhase(view.phase)) {
313 - setResultByEnvironment((previous) => new Map(previous).set(environmentId, view));
314 - }
315 - } catch (error) {
316 - if (isCurrentRequest()) {
317 - setErrorByEnvironment((previous) =>
318 - new Map(previous).set(
319 - environmentId,
320 - error instanceof Error ? error.message : "Provider update failed.",
321 - ),
322 - );
323 - }
324 - } finally {
325 - clearTimeout(expiry);
326 - if (isCurrentRequest()) {
327 - clearPending(environmentId);
328 - inFlightEnvironmentsRef.current.delete(environmentId);
329 - }
291 + return;
292 }
331 - },
332 - [clearPending, groupByEnvironment, onInteract, updateProvider],
333 - );
293 + const rejectedMessage = firstRejectedProviderUpdateMessage(results);
294 + if (rejectedMessage) {
295 + setErrorByEnvironment((previous) => new Map(previous).set(environmentId, rejectedMessage));
296 + return;
297 + }
298 + const view = getProviderUpdateProgressToastView({
299 + providers: collectProviderUpdateOutcomeSnapshots(results),
300 + providerCount,
301 + });
302 + // A stored view never re-polls, so persisting it would pin the row's
303 + // spinner forever once the pending flag expires. Drop it and let the
304 + // live per-environment provider state (pill) plus the pending expiry
305 + // drive the row, so it self-heals to whatever the backend actually did.
306 + if (isTerminalProviderUpdatePhase(view.phase)) {
307 + setResultByEnvironment((previous) => new Map(previous).set(environmentId, view));
308 + }
309 + });
310 + clearTimeout(expiry);
311 + if (!isCurrentRequest()) return;
312 + if (settled._tag === "Failure") {
313 + const error = squashAtomCommandFailure(settled);
314 + setErrorByEnvironment((previous) =>
315 + new Map(previous).set(
316 + environmentId,
317 + error instanceof Error ? error.message : "Provider update failed.",
318 + ),
319 + );
320 + }
321 + clearPending(environmentId);
322 + inFlightEnvironmentsRef.current.delete(environmentId);
323 + };
324
325 const rows = groups
326 .map((group) => ({
@@ -340,7 +330,7 @@ export function ProviderUpdateEnvironmentRows({
330 error: errorByEnvironment.get(group.environmentId),
331 result: resultByEnvironment.get(group.environmentId),
332 pill: getProviderUpdateSidebarPillView(group.candidates, {
343 - visibleAfterIso: visibleAfterIsoRef.current,
333 + visibleAfterIso,
334 }),
335 isPending: pendingEnvironments.has(group.environmentId),
336 }),