Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: plain chat availability check should not rely on window.Plain but only on env (#6867)

Marc Klingene251e60b53cb
diff --git a/web/src/components/nav/support-menu-dropdown.tsx b/web/src/components/nav/support-menu-dropdown.tsx
index e41ffeb946..92391c01c6 100644
--- a/web/src/components/nav/support-menu-dropdown.tsx
+++ b/web/src/components/nav/support-menu-dropdown.tsx
@@ -51,7 +51,7 @@ export const SupportMenuDropdown = () => {
icon: LifeBuoy,
});
} else {
- if (chatAvailable()) {
+ if (chatAvailable) {
items.push({
title: "Chat",
pathname: "#",
diff --git a/web/src/ee/features/billing/components/BillingSettings.tsx b/web/src/ee/features/billing/components/BillingSettings.tsx
index f067d8e6f5..98e18acec3 100644
--- a/web/src/ee/features/billing/components/BillingSettings.tsx
+++ b/web/src/ee/features/billing/components/BillingSettings.tsx
@@ -189,7 +189,7 @@ const BillingPortalOrPricingPageButton = () => {
// Do not show checkout or customer portal if manual plan is set in cloud config
if (organization?.cloudConfig?.plan) {
- if (chatAvailable())
+ if (chatAvailable)
return (
<Button
variant="secondary"
diff --git a/web/src/features/notifications/ErrorNotification.tsx b/web/src/features/notifications/ErrorNotification.tsx
index 90a548edca..fe580dd5fb 100644
--- a/web/src/features/notifications/ErrorNotification.tsx
+++ b/web/src/features/notifications/ErrorNotification.tsx
@@ -55,7 +55,7 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({
</div>
)}
- {isError && chatAvailable() && (
+ {isError && chatAvailable && (
<Button
variant="errorNotification"
size={"sm"}
diff --git a/web/src/features/support-chat/PlainChat.tsx b/web/src/features/support-chat/PlainChat.tsx
index 06cf232a59..bd5ee086fc 100644
--- a/web/src/features/support-chat/PlainChat.tsx
+++ b/web/src/features/support-chat/PlainChat.tsx
@@ -75,16 +75,16 @@ const PlainChat = () => {
export default PlainChat;
-export const chatAvailable = () => {
+export const chatAvailable = !!env.NEXT_PUBLIC_PLAIN_APP_ID;
+
+export const chatLoaded = () => {
return (
- !!env.NEXT_PUBLIC_PLAIN_APP_ID &&
- typeof window !== "undefined" &&
- window.Plain !== undefined
+ chatAvailable && typeof window !== "undefined" && window.Plain !== undefined
);
};
export const showChat = (): void => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
window.Plain.update({
hideLauncher: false,
});
@@ -92,7 +92,7 @@ export const showChat = (): void => {
};
export const hideChat = (): void => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
window.Plain.update({
hideLauncher: true,
});
@@ -100,20 +100,20 @@ export const hideChat = (): void => {
};
export const closeChat = (): void => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
window.Plain.close();
}
};
export const openChat = (): void => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
showChat();
window.Plain.open();
}
};
export const getUnreadMessageCount = (): number | null => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
return window.Plain.getUnreadMessageCount();
}
return null;
@@ -125,7 +125,7 @@ export const chatSetCustomer = (customer: {
emailHash?: string;
chatAvatarUrl?: string;
}) => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
window.Plain.update({
customerDetails: customer,
});
@@ -133,7 +133,7 @@ export const chatSetCustomer = (customer: {
};
export const chatSetThreadDetails = (p: { orgId?: string; plan?: Plan }) => {
- if (chatAvailable()) {
+ if (chatLoaded()) {
window.Plain.update({
threadDetails: {
...(p.orgId && {