Skip to content

Commit 5ffdd70

Browse files
perf(web): the sidebar update pill compiles with the React Compiler
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e8879a5 commit 5ffdd70

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ export const REACT_COMPILED_FILES = [
5959
"apps/web/src/components/ProviderUpdateEnvironmentRows.tsx",
6060
"apps/web/src/components/files/useDirectoryEntries.ts",
6161
"apps/web/src/components/files/FileBrowserPanel.tsx",
62+
"apps/web/src/components/sidebar/SidebarUpdatePill.tsx",
6263
] as const;

‎apps/web/src/components/sidebar/SidebarUpdatePill.tsx‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { DesktopBridge, DesktopUpdateState } from "@t3tools/contracts";
22
import { TriangleAlertIcon } from "lucide-react";
3-
import { type ComponentProps, useCallback, useEffect, useId, useRef, useState } from "react";
3+
import { type ComponentProps, useEffect, useId, useRef, useState } from "react";
44
import { flushSync } from "react-dom";
5+
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
56
import { isElectron } from "../../env";
67
import { useMediaQuery } from "../../hooks/useMediaQuery";
78
import { cn } from "../../lib/utils";
@@ -192,20 +193,28 @@ function SidebarUpdateControl() {
192193
const [isActionPending, setIsActionPending] = useState(false);
193194
const [isConfirmingEverything, setIsConfirmingEverything] = useState(false);
194195
const [checkAnimationKey, setCheckAnimationKey] = useState(0);
195-
const [isCheckAnimationLatched, setIsCheckAnimationLatched] = useState(false);
196196
const [releaseNotesPopoverHandle] = useState(() => PopoverCreateHandle());
197197
const suppressReleaseNotesFocusOpen = useRef(false);
198198
const releaseNotesPopupRef = useRef<HTMLDivElement>(null);
199199
const releaseNotesTriggerId = useId();
200200
const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
201201

202-
useEffect(() => {
202+
const updateStatus = state?.status;
203+
const [isCheckAnimationLatched, setIsCheckAnimationLatched] = useState(
204+
() => !prefersReducedMotion && updateStatus === "checking",
205+
);
206+
const [latchInputs, setLatchInputs] = useState({ prefersReducedMotion, updateStatus });
207+
if (
208+
latchInputs.prefersReducedMotion !== prefersReducedMotion ||
209+
latchInputs.updateStatus !== updateStatus
210+
) {
211+
setLatchInputs({ prefersReducedMotion, updateStatus });
203212
if (prefersReducedMotion) {
204213
setIsCheckAnimationLatched(false);
205-
} else if (state?.status === "checking") {
214+
} else if (updateStatus === "checking") {
206215
setIsCheckAnimationLatched(true);
207216
}
208-
}, [prefersReducedMotion, state?.status]);
217+
}
209218

210219
const action = state ? resolveDesktopUpdateButtonAction(state) : "none";
211220
const isDownloading = state?.status === "downloading";
@@ -259,7 +268,7 @@ function SidebarUpdateControl() {
259268
}
260269
}, [releaseNotesPopoverHandle, releaseNotesTriggerId, showReleaseNotesPopover]);
261270

262-
const handleAction = useCallback(async () => {
271+
const handleAction = async () => {
263272
const bridge = window.desktopBridge;
264273
if (isInteractionDisabled) return;
265274

@@ -330,14 +339,14 @@ function SidebarUpdateControl() {
330339
);
331340
})
332341
.finally(() => setIsActionPending(false));
333-
}, [action, isInteractionDisabled, prefersReducedMotion, runsEverything, state]);
342+
};
334343

335-
const runEverything = useCallback(async () => {
344+
const runEverything = async () => {
336345
const bridge = window.desktopBridge;
337346
setIsConfirmingEverything(false);
338347
setIsActionPending(true);
339-
try {
340-
await everything.run({
348+
const result = await settlePromise(() =>
349+
everything.run({
341350
...(bridge && action === "download"
342351
? {
343352
downloadLocal: (reportError) =>
@@ -347,28 +356,29 @@ function SidebarUpdateControl() {
347356
...(bridge && action !== "none"
348357
? { installLocal: (reportError) => installLocalUpdate(bridge, reportError) }
349358
: {}),
350-
});
351-
} catch (error) {
359+
}),
360+
);
361+
if (result._tag === "Failure") {
362+
const error = squashAtomCommandFailure(result);
352363
toastManager.add(
353364
stackedThreadToast({
354365
type: "error",
355366
title: "Could not update everything",
356367
description: error instanceof Error ? error.message : "An unexpected error occurred.",
357368
}),
358369
);
359-
} finally {
360-
setIsActionPending(false);
361370
}
362-
}, [action, everything]);
371+
setIsActionPending(false);
372+
};
363373

364-
const handleCheckAnimationIteration = useCallback(() => {
374+
const handleCheckAnimationIteration = () => {
365375
setIsCheckAnimationLatched(
366376
shouldContinueDesktopUpdateCheckAnimation({
367377
isChecking: state?.status === "checking",
368378
prefersReducedMotion,
369379
}),
370380
);
371-
}, [prefersReducedMotion, state?.status]);
381+
};
372382

373383
if (!isElectron && !runsEverything && !isRunningEverything) return null;
374384

0 commit comments

Comments
 (0)