Skip to content

Commit d2a5b9a

Browse files
mrmgcursoragent
andcommitted
fix(web): hide provider Update toast action while an update is running
Passing actionProps: undefined does not clear the previous CTA on toast update, so the prompt's Update button stayed clickable. Replace it with a defined empty action instead. Co-authored-by: Cursor <[email protected]>
1 parent 96bfa67 commit d2a5b9a

6 files changed

Lines changed: 69 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
providerUpdateNotificationKey,
2121
type ProviderUpdateToastView,
2222
} from "./ProviderUpdateLaunchNotification.logic";
23-
import { stackedThreadToast, toastManager } from "./ui/toast";
23+
import { hiddenToastActionProps, stackedThreadToast, toastManager } from "./ui/toast";
2424
import { useAtomCommand } from "../state/use-atom-command";
2525

2626
const seenProviderUpdateNotificationKeys = new Set<string>();
@@ -68,10 +68,10 @@ function updateProviderUpdateToast(input: {
6868
title: input.view.title,
6969
description: input.view.description,
7070
timeout: 0,
71-
// Base UI merges toast updates with the existing toast. Explicitly clear
72-
// the prompt action so its guarded Update handler cannot linger as a
73-
// visible no-op while the update is running (or after it succeeds).
74-
actionProps: undefined,
71+
// Base UI merges toast updates and omits `undefined` keys, so `undefined`
72+
// would leave the prompt's Update button in place. Replace it with a
73+
// defined empty action so the CTA cannot linger while the update runs.
74+
actionProps: hiddenToastActionProps,
7575
data: {
7676
hideCopyButton: true,
7777
...(input.view.dismissAfterVisibleMs !== undefined

‎apps/web/src/components/ui/toast.logic.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
22
import { assert, describe, it } from "vite-plus/test";
33
import {
44
buildVisibleToastLayout,
5+
hasVisibleToastAction,
56
shouldHideCollapsedToastContent,
67
shouldRenderThreadScopedToast,
78
} from "./toast.logic";
89

10+
describe("hasVisibleToastAction", () => {
11+
it("treats a labeled action as visible", () => {
12+
assert.equal(hasVisibleToastAction({ children: "Update" }), true);
13+
});
14+
15+
it("hides an explicit empty action used to clear a previous CTA", () => {
16+
assert.equal(hasVisibleToastAction({ children: null }), false);
17+
assert.equal(hasVisibleToastAction({ children: "" }), false);
18+
assert.equal(hasVisibleToastAction(undefined), false);
19+
});
20+
});
21+
922
describe("shouldHideCollapsedToastContent", () => {
1023
it("keeps a single visible toast readable", () => {
1124
assert.equal(shouldHideCollapsedToastContent(0, 1), false);

‎apps/web/src/components/ui/toast.logic.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
22

3+
/**
4+
* Base UI toast updates omit `undefined` fields, so callers that need to remove
5+
* an action must pass a defined `actionProps` whose `children` are empty.
6+
* Treat that payload (and missing children) as "no visible action".
7+
*/
8+
export function hasVisibleToastAction(actionProps: unknown): boolean {
9+
if (actionProps == null || typeof actionProps !== "object") {
10+
return false;
11+
}
12+
if (!("children" in actionProps)) {
13+
return false;
14+
}
15+
const children = actionProps.children;
16+
return children != null && children !== false && children !== "";
17+
}
18+
319
export function shouldHideCollapsedToastContent(
420
visibleToastIndex: number,
521
visibleToastCount: number,

‎apps/web/src/components/ui/toast.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
3232
import { resolveThreadRouteTarget } from "~/threadRoutes";
3333
import {
3434
buildVisibleToastLayout,
35+
hasVisibleToastAction,
3536
shouldHideCollapsedToastContent,
3637
shouldRenderThreadScopedToast,
3738
} from "./toast.logic";
@@ -287,7 +288,7 @@ function deriveToastBodyDescriptor(toast: {
287288
}): ToastBodyDescriptor {
288289
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
289290
const stackedActionLayout =
290-
toast.actionProps !== undefined && toast.data?.actionLayout === "stacked-end";
291+
hasVisibleToastAction(toast.actionProps) && toast.data?.actionLayout === "stacked-end";
291292
const actionVariant: NonNullable<ThreadToastData["actionVariant"]> =
292293
toast.data?.actionVariant ?? "default";
293294
const secondaryActionVariant: NonNullable<ThreadToastData["secondaryActionVariant"]> =
@@ -300,7 +301,7 @@ function deriveToastBodyDescriptor(toast: {
300301
const hasSecondaryAction = toast.data?.secondaryActionProps !== undefined;
301302
const hasTrailingControls =
302303
copyErrorText !== null ||
303-
toast.actionProps !== undefined ||
304+
hasVisibleToastAction(toast.actionProps) ||
304305
hasAdditionalActions ||
305306
hasSecondaryAction;
306307
const inlineContentEndPad = hasTrailingControls ? "pr-6" : "pr-10";
@@ -401,12 +402,12 @@ function ToastBodyContent({
401402
type="button"
402403
/>
403404
) : null}
404-
{actionProps ? (
405+
{hasVisibleToastAction(actionProps) ? (
405406
<Toast.Action
406407
className={cn(buttonVariants({ size: "xs", variant: actionVariant }), "shrink-0")}
407408
data-slot="toast-action"
408409
>
409-
{actionProps.children}
410+
{actionProps?.children}
410411
</Toast.Action>
411412
) : null}
412413
</div>
@@ -799,7 +800,7 @@ function AnchoredToasts() {
799800
);
800801
}
801802

802-
export { stackedThreadToast } from "./toastHelpers";
803+
export { hiddenToastActionProps, stackedThreadToast } from "./toastHelpers";
803804
export type { StackedThreadToastOptions } from "./toastHelpers";
804805

805806
export {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { assert, describe, it } from "vite-plus/test";
2+
3+
import { hiddenToastActionProps, stackedThreadToast } from "./toastHelpers";
4+
5+
describe("hiddenToastActionProps", () => {
6+
it("is a defined update payload so Base UI can replace a previous action", () => {
7+
assert.equal(hiddenToastActionProps.children, null);
8+
assert.equal(
9+
"actionProps" in stackedThreadToast({ type: "loading", title: "Updating" }),
10+
false,
11+
);
12+
assert.deepEqual(
13+
stackedThreadToast({
14+
type: "loading",
15+
title: "Updating",
16+
actionProps: hiddenToastActionProps,
17+
}).actionProps,
18+
hiddenToastActionProps,
19+
);
20+
});
21+
});

‎apps/web/src/components/ui/toastHelpers.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ export type StackedThreadToastOptions = {
1717
data?: Omit<ThreadToastData, "actionLayout">;
1818
};
1919

20+
/**
21+
* Defined `actionProps` that hide a previous toast CTA on `toastManager.update`.
22+
* Passing `actionProps: undefined` is a no-op because updates omit undefined keys.
23+
*/
24+
export const hiddenToastActionProps = {
25+
children: null,
26+
} as const satisfies Pick<ComponentPropsWithoutRef<"button">, "children">;
27+
2028
/**
2129
* Thread toast using the stacked body + bottom action row (copy for errors, CTA on its own row).
2230
*/

0 commit comments

Comments
 (0)