TypeScript
perf(web): the sidebar update pill compiles with the React Compiler (#20484)
Julius Marminge62861700d801
diff --git a/apps/web/reactCompiledFiles.ts b/apps/web/reactCompiledFiles.tsindex fbbc30589ef..c38e1b43bab 100644--- a/apps/web/reactCompiledFiles.ts+++ b/apps/web/reactCompiledFiles.ts@@ -59,4 +59,5 @@ export const REACT_COMPILED_FILES = ["apps/web/src/components/ProviderUpdateEnvironmentRows.tsx","apps/web/src/components/files/useDirectoryEntries.ts","apps/web/src/components/files/FileBrowserPanel.tsx",+ "apps/web/src/components/sidebar/SidebarUpdatePill.tsx",] as const;diff --git a/apps/web/src/components/sidebar/SidebarUpdatePill.tsx b/apps/web/src/components/sidebar/SidebarUpdatePill.tsxindex 823427ecb15..cfe0ba45682 100644--- a/apps/web/src/components/sidebar/SidebarUpdatePill.tsx+++ b/apps/web/src/components/sidebar/SidebarUpdatePill.tsx@@ -1,7 +1,8 @@import type { DesktopBridge, DesktopUpdateState } from "@t3tools/contracts";import { TriangleAlertIcon } from "lucide-react";-import { type ComponentProps, useCallback, useEffect, useId, useRef, useState } from "react";+import { type ComponentProps, useEffect, useId, useRef, useState } from "react";import { flushSync } from "react-dom";+import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";import { isElectron } from "../../env";import { useMediaQuery } from "../../hooks/useMediaQuery";import { cn } from "../../lib/utils";@@ -192,20 +193,28 @@ function SidebarUpdateControl() {const [isActionPending, setIsActionPending] = useState(false);const [isConfirmingEverything, setIsConfirmingEverything] = useState(false);const [checkAnimationKey, setCheckAnimationKey] = useState(0);- const [isCheckAnimationLatched, setIsCheckAnimationLatched] = useState(false);const [releaseNotesPopoverHandle] = useState(() => PopoverCreateHandle());const suppressReleaseNotesFocusOpen = useRef(false);const releaseNotesPopupRef = useRef<HTMLDivElement>(null);const releaseNotesTriggerId = useId();const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");- useEffect(() => {+ const updateStatus = state?.status;+ const [isCheckAnimationLatched, setIsCheckAnimationLatched] = useState(+ () => !prefersReducedMotion && updateStatus === "checking",+ );+ const [latchInputs, setLatchInputs] = useState({ prefersReducedMotion, updateStatus });+ if (+ latchInputs.prefersReducedMotion !== prefersReducedMotion ||+ latchInputs.updateStatus !== updateStatus+ ) {+ setLatchInputs({ prefersReducedMotion, updateStatus });if (prefersReducedMotion) {setIsCheckAnimationLatched(false);- } else if (state?.status === "checking") {+ } else if (updateStatus === "checking") {setIsCheckAnimationLatched(true);}- }, [prefersReducedMotion, state?.status]);+ }const action = state ? resolveDesktopUpdateButtonAction(state) : "none";const isDownloading = state?.status === "downloading";@@ -259,7 +268,7 @@ function SidebarUpdateControl() {}}, [releaseNotesPopoverHandle, releaseNotesTriggerId, showReleaseNotesPopover]);- const handleAction = useCallback(async () => {+ const handleAction = async () => {const bridge = window.desktopBridge;if (isInteractionDisabled) return;@@ -330,14 +339,14 @@ function SidebarUpdateControl() {);}).finally(() => setIsActionPending(false));- }, [action, isInteractionDisabled, prefersReducedMotion, runsEverything, state]);+ };- const runEverything = useCallback(async () => {+ const runEverything = async () => {const bridge = window.desktopBridge;setIsConfirmingEverything(false);setIsActionPending(true);- try {- await everything.run({+ const result = await settlePromise(() =>+ everything.run({...(bridge && action === "download"? {downloadLocal: (reportError) =>@@ -347,8 +356,10 @@ function SidebarUpdateControl() {...(bridge && action !== "none"? { installLocal: (reportError) => installLocalUpdate(bridge, reportError) }: {}),- });- } catch (error) {+ }),+ );+ if (result._tag === "Failure") {+ const error = squashAtomCommandFailure(result);toastManager.add(stackedThreadToast({type: "error",@@ -356,19 +367,18 @@ function SidebarUpdateControl() {description: error instanceof Error ? error.message : "An unexpected error occurred.",}),);- } finally {- setIsActionPending(false);}- }, [action, everything]);+ setIsActionPending(false);+ };- const handleCheckAnimationIteration = useCallback(() => {+ const handleCheckAnimationIteration = () => {setIsCheckAnimationLatched(shouldContinueDesktopUpdateCheckAnimation({isChecking: state?.status === "checking",prefersReducedMotion,}),);- }, [prefersReducedMotion, state?.status]);+ };if (!isElectron && !runsEverything && !isRunningEverything) return null;