Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(chat): a public chat link no longer sends past visitors to sign-in (#17097)

Hazem Adelf6f82a14197e
diff --git a/packages/web/src/app/routes/chat/index.tsx b/packages/web/src/app/routes/chat/index.tsx
index 282fb4ef4b9..ad868f73fb3 100644
--- a/packages/web/src/app/routes/chat/index.tsx
+++ b/packages/web/src/app/routes/chat/index.tsx
@@ -1,4 +1,3 @@
-import { isNil } from '@activepieces/core-utils';
import { USE_DRAFT_QUERY_PARAM_NAME } from '@activepieces/shared';
import { nanoid } from 'nanoid';
import { useState, useEffect } from 'react';
@@ -6,9 +5,7 @@ import { useParams } from 'react-router-dom';
import { useSearchParam } from 'react-use';
import { ChatDrawerSource } from '@/app/builder/types';
-import { LoadingScreen } from '@/components/custom/loading-screen';
import { Messages } from '@/features/chat';
-import { flowHooks } from '@/features/flows';
import { ChatNotFound, FlowChat } from './flow-chat';
@@ -19,9 +16,6 @@ export function ChatPage() {
const [messages, setMessages] = useState<Messages>([]);
const [chatSessionId, setChatSessionId] = useState<string | null>(null);
- const { data: flow, isLoading } = flowHooks.useGetFlow({
- flowId: flowId ?? '',
- });
useEffect(() => {
if (!chatSessionId) {
setChatSessionId(nanoid());
@@ -35,16 +29,10 @@ export function ChatPage() {
if (!flowId) {
return <ChatNotFound />;
}
- if (isLoading) {
- return <LoadingScreen />;
- }
-
- const isDraft =
- hasDraftSearchParam || (flow && isNil(flow.publishedVersionId));
return (
<FlowChat
flowId={flowId}
- mode={isDraft ? ChatDrawerSource.TEST_FLOW : null}
+ mode={hasDraftSearchParam ? ChatDrawerSource.TEST_FLOW : null}
onSendingMessage={() => {}}
onError={(error) => {
console.error('Chat error:', error);
diff --git a/packages/web/test/app/routes/chat/public-chat-page.test.tsx b/packages/web/test/app/routes/chat/public-chat-page.test.tsx
new file mode 100644
index 00000000000..7b22895a77e
--- /dev/null
+++ b/packages/web/test/app/routes/chat/public-chat-page.test.tsx
@@ -0,0 +1,58 @@
+/**
+ * @vitest-environment jsdom
+ */
+import { cleanup, render, screen } from '@testing-library/react';
+import { MemoryRouter, Route, Routes } from 'react-router-dom';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { ChatDrawerSource } from '@/app/builder/types';
+import { ChatPage } from '@/app/routes/chat';
+
+const { useGetFlow } = vi.hoisted(() => ({
+ useGetFlow: vi.fn(() => ({ data: null, isLoading: false })),
+}));
+
+vi.mock('@/features/flows', () => ({
+ flowHooks: { useGetFlow },
+}));
+
+vi.mock('@/app/routes/chat/flow-chat', () => ({
+ FlowChat: ({ mode }: { mode: string | null }) => (
+ <div>chat mode: {String(mode)}</div>
+ ),
+ ChatNotFound: () => <div>not found</div>,
+}));
+
+afterEach(() => {
+ cleanup();
+ useGetFlow.mockClear();
+});
+
+describe('public chat page', () => {
+ it('opens the chat without reading the flow through the signed-in API', () => {
+ renderAt('/chats/flow-1');
+
+ expect(screen.getByText('chat mode: null')).toBeTruthy();
+ expect(useGetFlow).not.toHaveBeenCalled();
+ });
+
+ it('opens the draft chat when the link asks for it', () => {
+ renderAt('/chats/flow-1?useDraft=true');
+
+ expect(
+ screen.getByText(`chat mode: ${ChatDrawerSource.TEST_FLOW}`),
+ ).toBeTruthy();
+ expect(useGetFlow).not.toHaveBeenCalled();
+ });
+});
+
+function renderAt(path: string) {
+ window.history.pushState({}, '', path);
+ render(
+ <MemoryRouter initialEntries={[path]}>
+ <Routes>
+ <Route path="/chats/:flowId" element={<ChatPage />} />
+ </Routes>
+ </MemoryRouter>,
+ );
+}