Skip to content

Commit 8254505

Browse files
perf(web): the provider update launch notification compiles with the React Compiler (#20577)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a72b58e commit 8254505

1 file changed

Lines changed: 25 additions & 30 deletions

File tree

‎apps/web/src/components/ProviderUpdateLaunchNotification.tsx‎

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useNavigate } from "@tanstack/react-router";
22
import { DownloadIcon } from "lucide-react";
3-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3+
import { useEffect, useRef, useState } from "react";
44

5+
import { useStableCallback } from "~/hooks/useStableCallback";
56
import { useEnvironments } from "~/state/environments";
67
import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
78
import { useDismissedProviderUpdateNotificationKeys } from "../providerUpdateDismissal";
@@ -18,10 +19,8 @@ import { stackedThreadToast, toastManager } from "./ui/toast";
1819

1920
function useHasLocalSecondaryEnvironment(): boolean {
2021
const { environments } = useEnvironments();
21-
return useMemo(
22-
() =>
23-
environments.some((environment) => isDesktopLocalConnectionTarget(environment.entry.target)),
24-
[environments],
22+
return environments.some((environment) =>
23+
isDesktopLocalConnectionTarget(environment.entry.target),
2524
);
2625
}
2726

@@ -53,7 +52,6 @@ function ProviderUpdateEnvironmentsNotification() {
5352
readonly toastId: ProviderUpdateToastId;
5453
readonly key: string;
5554
} | null>(null);
56-
const notificationKeyRef = useRef<string | null>(null);
5755
// Whether the user has triggered an update from the current toast. Until they
5856
// do, the prompt is replaced when the available updates change; afterward it
5957
// is kept so in-progress rows are not torn down.
@@ -68,36 +66,41 @@ function ProviderUpdateEnvironmentsNotification() {
6866
};
6967
}, []);
7068

71-
const updateGroups = useMemo(() => environmentGroupsWithUpdates(groups), [groups]);
72-
const notificationKey = useMemo(() => localEnvironmentUpdateNotificationKey(groups), [groups]);
73-
useEffect(() => {
74-
notificationKeyRef.current = notificationKey;
75-
}, [notificationKey]);
76-
77-
const candidateUnion = useMemo(
78-
() => collectProviderUpdateCandidates(updateGroups.flatMap((group) => group.candidates)),
79-
[updateGroups],
69+
const updateGroups = environmentGroupsWithUpdates(groups);
70+
const notificationKey = localEnvironmentUpdateNotificationKey(groups);
71+
const candidateUnion = collectProviderUpdateCandidates(
72+
updateGroups.flatMap((group) => group.candidates),
8073
);
8174

8275
const [settleGraceElapsed, setSettleGraceElapsed] = useState(false);
76+
// The grace period restarts with the next settling phase.
77+
if (!isAnySettling && settleGraceElapsed) {
78+
setSettleGraceElapsed(false);
79+
}
8380
useEffect(() => {
84-
if (!isAnySettling) {
85-
setSettleGraceElapsed(false);
86-
return;
87-
}
81+
if (!isAnySettling) return;
8882
const timer = setTimeout(() => setSettleGraceElapsed(true), SETTLING_GRACE_MS);
8983
return () => clearTimeout(timer);
9084
}, [isAnySettling]);
9185
const isGated = isAnySettling && !settleGraceElapsed;
9286

93-
const openProviderSettings = useCallback(() => {
87+
const openProviderSettings = () => {
9488
const active = activeToastRef.current;
9589
if (active !== null) {
9690
toastManager.close(active.toastId);
9791
activeToastRef.current = null;
9892
}
9993
void navigate({ to: "/settings/providers" });
100-
}, [navigate]);
94+
};
95+
96+
// The toast closes long after the effect that opened it, so it dismisses the key
97+
// the updates have moved to by then.
98+
const dismissPrompt = useStableCallback(() => {
99+
if (notificationKey) {
100+
dismissNotificationKey(notificationKey);
101+
}
102+
activeToastRef.current = null;
103+
});
101104

102105
useEffect(() => {
103106
const canShowPrompt =
@@ -124,14 +127,6 @@ function ProviderUpdateEnvironmentsNotification() {
124127
seenProviderUpdateNotificationKeys.add(notificationKey);
125128
hasInteractedRef.current = false;
126129

127-
const dismissPrompt = () => {
128-
const liveKey = notificationKeyRef.current;
129-
if (liveKey) {
130-
dismissNotificationKey(liveKey);
131-
}
132-
activeToastRef.current = null;
133-
};
134-
135130
const toastId = toastManager.add(
136131
stackedThreadToast({
137132
type: "warning",
@@ -165,7 +160,7 @@ function ProviderUpdateEnvironmentsNotification() {
165160
isGated,
166161
candidateUnion,
167162
dismissedNotificationKeys,
168-
dismissNotificationKey,
163+
dismissPrompt,
169164
openProviderSettings,
170165
]);
171166

0 commit comments

Comments
 (0)