fix(web): hide provider Update toast action while an update is running (#6544)

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Mark GriffinandCursor authored and GitHub committed 2026-08-15 14:03:14 +02:00
1 parent 51c6daa3bd
commit 3cde99b259
6 files changed
+69 -10

No files matched your search

@@ -20,7 +20,7 @@ import {
providerUpdateNotificationKey,
type ProviderUpdateToastView,
} from "./ProviderUpdateLaunchNotification.logic";
import { stackedThreadToast, toastManager } from "./ui/toast";
import { hiddenToastActionProps, stackedThreadToast, toastManager } from "./ui/toast";
import { useAtomCommand } from "../state/use-atom-command";
const seenProviderUpdateNotificationKeys = new Set<string>();
@@ -68,10 +68,10 @@ function updateProviderUpdateToast(input: {
title: input.view.title,
description: input.view.description,
timeout: 0,
// Base UI merges toast updates with the existing toast. Explicitly clear
// the prompt action so its guarded Update handler cannot linger as a
// visible no-op while the update is running (or after it succeeds).
actionProps: undefined,
// Base UI merges toast updates and omits `undefined` keys, so `undefined`
// would leave the prompt's Update button in place. Replace it with a
// defined empty action so the CTA cannot linger while the update runs.
actionProps: hiddenToastActionProps,
data: {
hideCopyButton: true,
...(input.view.dismissAfterVisibleMs !== undefined
@@ -2,10 +2,23 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
import { assert, describe, it } from "vite-plus/test";
import {
buildVisibleToastLayout,
hasVisibleToastAction,
shouldHideCollapsedToastContent,
shouldRenderThreadScopedToast,
} from "./toast.logic";
describe("hasVisibleToastAction", () => {
it("treats a labeled action as visible", () => {
assert.equal(hasVisibleToastAction({ children: "Update" }), true);
});
it("hides an explicit empty action used to clear a previous CTA", () => {
assert.equal(hasVisibleToastAction({ children: null }), false);
assert.equal(hasVisibleToastAction({ children: "" }), false);
assert.equal(hasVisibleToastAction(undefined), false);
});
});
describe("shouldHideCollapsedToastContent", () => {
it("keeps a single visible toast readable", () => {
assert.equal(shouldHideCollapsedToastContent(0, 1), false);
+16
View File
@@ -1,5 +1,21 @@
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
/**
* Base UI toast updates omit `undefined` fields, so callers that need to remove
* an action must pass a defined `actionProps` whose `children` are empty.
* Treat that payload (and missing children) as "no visible action".
*/
export function hasVisibleToastAction(actionProps: unknown): boolean {
if (actionProps == null || typeof actionProps !== "object") {
return false;
}
if (!("children" in actionProps)) {
return false;
}
const children = actionProps.children;
return children != null && children !== false && children !== "";
}
export function shouldHideCollapsedToastContent(
visibleToastIndex: number,
visibleToastCount: number,
+6 -5
View File
@@ -32,6 +32,7 @@ import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
import { resolveThreadRouteTarget } from "~/threadRoutes";
import {
buildVisibleToastLayout,
hasVisibleToastAction,
shouldHideCollapsedToastContent,
shouldRenderThreadScopedToast,
} from "./toast.logic";
@@ -288,7 +289,7 @@ function deriveToastBodyDescriptor(toast: {
}): ToastBodyDescriptor {
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
const stackedActionLayout =
toast.actionProps !== undefined && toast.data?.actionLayout === "stacked-end";
hasVisibleToastAction(toast.actionProps) && toast.data?.actionLayout === "stacked-end";
const actionVariant: NonNullable<ThreadToastData["actionVariant"]> =
toast.data?.actionVariant ?? "default";
const secondaryActionVariant: NonNullable<ThreadToastData["secondaryActionVariant"]> =
@@ -301,7 +302,7 @@ function deriveToastBodyDescriptor(toast: {
const hasSecondaryAction = toast.data?.secondaryActionProps !== undefined;
const hasTrailingControls =
copyErrorText !== null ||
toast.actionProps !== undefined ||
hasVisibleToastAction(toast.actionProps) ||
hasAdditionalActions ||
hasSecondaryAction;
const inlineContentEndPad = hasTrailingControls ? "pr-6" : "pr-10";
@@ -400,12 +401,12 @@ function ToastBodyContent({
variant={secondaryActionVariant}
/>
) : null}
{actionProps ? (
{hasVisibleToastAction(actionProps) ? (
<Toast.Action
className={cn(buttonVariants({ size: "xs", variant: actionVariant }), "shrink-0")}
data-slot="toast-action"
>
{actionProps.children}
{actionProps?.children}
</Toast.Action>
) : null}
</div>
@@ -798,7 +799,7 @@ function AnchoredToasts() {
);
}
export { stackedThreadToast } from "./toastHelpers";
export { hiddenToastActionProps, stackedThreadToast } from "./toastHelpers";
export type { StackedThreadToastOptions } from "./toastHelpers";
export {
@@ -0,0 +1,21 @@
import { assert, describe, it } from "vite-plus/test";
import { hiddenToastActionProps, stackedThreadToast } from "./toastHelpers";
describe("hiddenToastActionProps", () => {
it("is a defined update payload so Base UI can replace a previous action", () => {
assert.equal(hiddenToastActionProps.children, null);
assert.equal(
"actionProps" in stackedThreadToast({ type: "loading", title: "Updating" }),
false,
);
assert.deepEqual(
stackedThreadToast({
type: "loading",
title: "Updating",
actionProps: hiddenToastActionProps,
}).actionProps,
hiddenToastActionProps,
);
});
});
@@ -17,6 +17,14 @@ export type StackedThreadToastOptions = {
data?: Omit<ThreadToastData, "actionLayout">;
};
/**
* Defined `actionProps` that hide a previous toast CTA on `toastManager.update`.
* Passing `actionProps: undefined` is a no-op because updates omit undefined keys.
*/
export const hiddenToastActionProps = {
children: null,
} as const satisfies Pick<ComponentPropsWithoutRef<"button">, "children">;
/**
* Thread toast using the stacked body + bottom action row (copy for errors, CTA on its own row).
*/