Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(chat): a pinned page fetches again when its bot replaces it

Bugfixer 27bffd157fef8
diff --git a/src/components/WebPanelPage.test.ts b/src/components/WebPanelPage.test.ts
index 0a936e80a4..39b4c03d24 100644
--- a/src/components/WebPanelPage.test.ts
+++ b/src/components/WebPanelPage.test.ts
@@ -9,7 +9,7 @@ const fixture = vi.hoisted(() => ({
panels: [] as Array<{ id: string; name: string; url?: string; page?: { botId: string; threadId: string; messageId: string } }>,
setWebPanels: vi.fn(),
fetchAppDocument: vi.fn(async (_threadId: string, _messageId: string, _signal?: AbortSignal): Promise<unknown> => ({ srcdoc: "<p>hi</p>", can: {} })),
- state: { webPanelId: "panel-1" } as { webPanelId?: string },
+ state: { webPanelId: "panel-1" } as { webPanelId?: string; bots?: unknown[] },
dispatch: vi.fn(),
api: vi.fn(async (_path: string, _init?: unknown): Promise<unknown> => ({ framing: "allowed" })),
}));
@@ -124,4 +124,17 @@ describe("a pinned web panel's page", () => {
act(() => [...host.querySelectorAll("button")].find((button) => button.textContent === "Unpin")!.click());
expect(fixture.setWebPanels).toHaveBeenCalledWith([{ id: "panel-2", name: "CI", url: "https://ci.example/" }]);
});
+
+ it("fetches a pinned chat page again when the bot replaces it in a loaded chat", async () => {
+ fixture.panels = [{ id: "panel-1", name: "Sales", page: { botId: "b1", threadId: "t1", messageId: "m1" } }];
+ const withRev = (rev: number) => [{ id: "b1", threadId: "t1", messages: [{ id: "m1", kind: "app", app: { title: "Sales", source: "html", doc: "d1", rev } }] }];
+ fixture.state = { webPanelId: "panel-1", bots: withRev(1) };
+ fixture.fetchAppDocument.mockClear();
+ await act(async () => root.render(createElement(WebPanelPage)));
+ expect(fixture.fetchAppDocument).toHaveBeenCalledTimes(1);
+ fixture.state = { webPanelId: "panel-1", bots: withRev(2) };
+ await act(async () => root.render(createElement(WebPanelPage)));
+ expect(fixture.fetchAppDocument).toHaveBeenCalledTimes(2);
+ fixture.state = { webPanelId: "panel-1" };
+ });
});
diff --git a/src/components/WebPanelPage.tsx b/src/components/WebPanelPage.tsx
index bd248749d6..b5a0bc30ae 100644
--- a/src/components/WebPanelPage.tsx
+++ b/src/components/WebPanelPage.tsx
@@ -11,7 +11,7 @@ import { t } from "@/lib/i18n";
import { setWebPanels, useWebPanels } from "@/lib/web-panel-preferences";
import { isAppOrigin, type PinnedChatPage, type WebPanel } from "@/lib/web-panels";
import { api } from "@/state/api";
-import { useStore } from "@/state/store";
+import { useStore, type Bot } from "@/state/store";
import type { AppDocument } from "../../shared/app";
import { AppDocumentError, fetchAppDocument } from "./app/app-api";
import { AppFrame, type AppFrameHandle } from "./app/AppFrame";
@@ -97,8 +97,18 @@ export function WebPanelPage() {
type PageLoad = { doc: AppDocument } | { failure: string };
+/** The page's current version when its chat is loaded in the app ("" when it isn't): a bot replacing the page, or a
+ * live folder it watches changing, updates this, and the pinned view fetches the new page, as the chat does. */
+function storedPageVersion(bots: readonly Bot[] | undefined, page: PinnedChatPage): string {
+ const bot = bots?.find((candidate) => candidate.id === page.botId);
+ if (!bot || bot.threadId !== page.threadId) return "";
+ const app = bot.messages.find((message) => message.id === page.messageId)?.app;
+ return app ? `${app.doc}:${app.rev ?? 0}` : "";
+}
+
function PinnedChatPageView({ panel, page, panels }: { panel: WebPanel; page: PinnedChatPage; panels: readonly WebPanel[] }) {
- const { dispatch } = useStore();
+ const { state, dispatch } = useStore();
+ const version = storedPageVersion(state.bots, page);
const [reloads, setReloads] = useState(0);
const [load, setLoad] = useState<PageLoad | null>(null);
const handle = useRef<AppFrameHandle | null>(null);
@@ -114,7 +124,7 @@ function PinnedChatPageView({ panel, page, panels }: { panel: WebPanel; page: Pi
},
);
return () => controller.abort();
- }, [page.threadId, page.messageId, reloads]);
+ }, [page.threadId, page.messageId, reloads, version]);
const unpin = () => setWebPanels(panels.filter((entry) => entry.id !== panel.id));
@@ -140,7 +150,7 @@ function PinnedChatPageView({ panel, page, panels }: { panel: WebPanel; page: Pi
{load && "doc" in load ? (
<div className="relative min-h-0 flex-1">
<AppFrame
- key={reloads}
+ key={`${reloads}:${version}`}
doc={load.doc}
botId={page.botId}
threadId={page.threadId}