Skip to content

Commit aae451f

Browse files
committed
fix(site/src/pages/AgentsPage): clear the New chat draft only on the plain composer route
1 parent 6e06900 commit aae451f

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

‎site/src/pages/AgentsPage/AgentCreatePage.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { act, screen, waitFor, within } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import { HttpResponse, http } from "msw";
4+
import { onlineManager } from "react-query";
45
import { toast } from "sonner";
56
import {
67
afterEach,
@@ -347,6 +348,29 @@ describe("AgentCreatePage project assignment", () => {
347348
await screen.findByRole("heading", { name: MockChatProject.name });
348349
});
349350

351+
it("keeps loading while the refetch of a cached list is paused offline", async () => {
352+
enableExperiments("chat-projects");
353+
serveProjects(MockChatProject);
354+
355+
const { router, queryClient } = renderAgentsRoutes("/agents");
356+
await screen.findByRole("button", { name: "Create chat" });
357+
// The test client's offlineFirst mode would fetch anyway; the app
358+
// uses the default online mode, which pauses the fetch.
359+
queryClient.setQueryDefaults(chatProjectsKey, { networkMode: "online" });
360+
onlineManager.setOnline(false);
361+
try {
362+
act(() => {
363+
queryClient.setQueryData(chatProjectsKey, []);
364+
void router.navigate(projectPath(MockChatProject.id));
365+
});
366+
367+
await screen.findByRole("status", { name: "Loading project" });
368+
expect(screen.queryByText("Project not found")).not.toBeInTheDocument();
369+
} finally {
370+
onlineManager.setOnline(true);
371+
}
372+
});
373+
350374
it("shows the plain composer on /agents after a project list is cached", async () => {
351375
enableExperiments("chat-projects");
352376
serveProjects(MockChatProject);

‎site/src/pages/AgentsPage/AgentsPageLayout.test.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const renderLayout = (route = "/agents") =>
1313
children: [
1414
{ index: true, element: null },
1515
{ path: "projects/:projectId", element: null },
16+
{ path: "automations", element: null },
17+
{ path: "board", element: null },
1618
],
1719
});
1820

@@ -48,12 +50,16 @@ describe("AgentsPageLayout New chat", () => {
4850
},
4951
);
5052

51-
it("keeps the plain composer's draft when leaving a project composer", async () => {
53+
it.each([
54+
"/agents/projects/project-1",
55+
"/agents/automations",
56+
"/agents/board",
57+
])("keeps the plain composer's draft when leaving %s", async (route) => {
5258
vi.spyOn(API.experimental, "getChats").mockResolvedValue([]);
5359
localStorage.setItem(emptyInputStorageKey, "draft the user typed earlier");
5460
const user = userEvent.setup();
5561

56-
const { router } = renderLayout("/agents/projects/project-1");
62+
const { router } = renderLayout(route);
5763
await user.click(await screen.findByRole("link", { name: "New chat" }));
5864

5965
await waitFor(() => expect(router.state.location.pathname).toBe("/agents"));

‎site/src/pages/AgentsPage/AgentsPageLayout.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const AgentsPageLayout: React.FC = () => {
177177
const navigate = useNavigate();
178178
const location = useLocation();
179179
const [searchParams, setSearchParams] = useSearchParams();
180-
const { agentId, projectId } = useParams();
180+
const { agentId } = useParams();
181181
const { permissions, user } = useAuthenticated();
182182
const { organizations } = useDashboard();
183183
const organizationName = getDefaultOrganizationName(organizations);
@@ -535,10 +535,9 @@ const AgentsPageLayout: React.FC = () => {
535535
// A composer prefilled from a prompt link shows the link's text,
536536
// not the draft, so the draft is preserved there too. A debug link
537537
// can fall back to the draft-backed composer, so it is not exempt.
538-
// A project composer keeps its own draft, so leaving it keeps this one.
538+
// Other routes, such as a project composer, keep this draft too.
539539
if (
540-
!agentId &&
541-
!projectId &&
540+
location.pathname.replace(/\/$/, "") === "/agents" &&
542541
readDeepLinkState(location.state).prompt === undefined
543542
) {
544543
localStorage.removeItem(emptyInputStorageKey);

0 commit comments

Comments
 (0)