Skip to content
TypeScript

fix(web): bound disconnected send toasts (#9592)

maria07891e9569c8
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 97e63a2bd0a..1b9c106fe52 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -1335,6 +1335,8 @@ function chatActionErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : "An error occurred.";
}
+const ENVIRONMENT_UNAVAILABLE_SEND_TOAST_TRAIL_SIZE = 3;
+
/**
* Drops the send-time anchored end space. That space is what holds a sent
* message near the top while its turn streams, and it keeps LegendList's
@@ -1641,6 +1643,7 @@ function ChatViewContent(props: ChatViewProps) {
const attachmentPreviewHandoffByMessageIdRef = useRef<Record<string, string[]>>({});
const attachmentPreviewPromotionInFlightByMessageIdRef = useRef<Record<string, true>>({});
const sendInFlightRef = useRef(false);
+ const environmentUnavailableSendToastSlotRef = useRef(0);
const feedbackUploadsInFlightRef = useRef(new Set<string>());
const terminalUiOpenByThreadRef = useRef<Record<string, boolean>>({});
@@ -6073,13 +6076,17 @@ function ChatViewContent(props: ChatViewProps) {
return;
}
if (activeEnvironmentUnavailable) {
- toastManager.add(
- stackedThreadToast({
+ const toastSlot = environmentUnavailableSendToastSlotRef.current;
+ environmentUnavailableSendToastSlotRef.current =
+ (toastSlot + 1) % ENVIRONMENT_UNAVAILABLE_SEND_TOAST_TRAIL_SIZE;
+ toastManager.add({
+ ...stackedThreadToast({
type: "warning",
title: "Not connected: message not sent",
description: "Reconnecting to the environment. Try again once it is connected.",
}),
- );
+ id: `chat-send-environment-unavailable:${toastSlot}`,
+ });
return;
}
if (activePendingProgress) {