From b5a3fa76d8b3a98ff89f86395d0a2757511ab110 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 4 Oct 2026 12:08:05 +1100 Subject: [PATCH] fix(chat): stop the recording chat's scroll effect from returning a Promise Current Chromium returns a Promise from scrollIntoView, and the effect's arrow returned it, so React logged an effect error when the chat opened. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../__tests__/recording-chat-tab.test.tsx | 49 +++++++++++++++++++ .../components/recording/chat-tab.tsx | 5 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 nextjs-frontend/__tests__/recording-chat-tab.test.tsx diff --git a/nextjs-frontend/__tests__/recording-chat-tab.test.tsx b/nextjs-frontend/__tests__/recording-chat-tab.test.tsx new file mode 100644 index 000000000..781fe55e7 --- /dev/null +++ b/nextjs-frontend/__tests__/recording-chat-tab.test.tsx @@ -0,0 +1,49 @@ +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; + +import { ChatTab } from "@/components/recording/chat-tab"; +import { RecordingProvider, type RecordingCtx } from "@/components/recording/context"; +import { PlayerProvider } from "@/components/player/media"; +import { TooltipProvider } from "@/components/ui/tooltip"; + +jest.mock("@/app/openapi-client", () => ({ + Chats: { + listChats: () => Promise.resolve({ data: [], response: { ok: true, status: 200 } }), + getChat: () => Promise.resolve({ data: null, response: { ok: true, status: 200 } }), + }, +})); +jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) })); + +beforeAll(() => { + // Current Chromium returns a Promise from scrollIntoView + Element.prototype.scrollIntoView = jest.fn(() => Promise.resolve()) as unknown as Element["scrollIntoView"]; +}); + +it("opens with a quote from Ask in chat without React's effect error", async () => { + const error = jest.spyOn(console, "error").mockImplementation(() => {}); + const ctx = { + id: 9, + ns: "pods", + member: true, + model: { segments: [] }, + chatDraft: "> “the capsid model” (0:04)\n\n", + clearChatDraft: () => {}, + } as unknown as RecordingCtx; + const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } }); + render( + + + + + + + + + , + ); + + expect(await screen.findByLabelText("Ask about this recording")).toHaveValue("> “the capsid model” (0:04)\n\n"); + expect(error.mock.calls.flat().join(" ")).not.toMatch(/must not return anything besides a function/); + error.mockRestore(); +}); diff --git a/nextjs-frontend/components/recording/chat-tab.tsx b/nextjs-frontend/components/recording/chat-tab.tsx index 4f232b6e6..758aaa0fd 100644 --- a/nextjs-frontend/components/recording/chat-tab.tsx +++ b/nextjs-frontend/components/recording/chat-tab.tsx @@ -80,7 +80,10 @@ function ChatPanel() { box.current?.setSelectionRange(n, n); }); }, [chatDraft, clearChatDraft]); - useEffect(() => end.current?.scrollIntoView({ block: "end" }), [answer?.text, chat.data?.messages?.length]); + // Braces: scrollIntoView returns a Promise in current Chromium, and an effect may only return a clean-up function. + useEffect(() => { + end.current?.scrollIntoView({ block: "end" }); + }, [answer?.text, chat.data?.messages?.length]); useEffect(() => () => abort.current?.abort(), []); const send = async () => {