Skip to content

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

Rename opens on the bot you asked for, every time

milind-sonic08816589f43
diff --git a/src/components/RenameTitle.request.test.ts b/src/components/RenameTitle.request.test.ts
index 22286ca930..505a484181 100644
--- a/src/components/RenameTitle.request.test.ts
+++ b/src/components/RenameTitle.request.test.ts
@@ -23,3 +23,30 @@ it("starts editing when a new edit request arrives, never for the one it mounted
await act(async () => root.unmount());
host.remove();
});
+
+it("stays put when the rename request moves on to another bot, and only the bot asked for opens", async () => {
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+ const host = document.createElement("div");
+ document.body.append(host);
+ const root = createRoot(host);
+ const request = (botId: string, ask: { botId: string; nonce: number } | null) => (ask?.botId === botId ? ask.nonce : 0);
+ const draw = (ask: { botId: string; nonce: number } | null) => act(async () => {
+ root.render(createElement("div", null,
+ createElement(RenameTitle, { key: "a", value: "Atlas", onCommit: vi.fn(), editRequest: request("a", ask) }),
+ createElement(RenameTitle, { key: "b", value: "Birch", onCommit: vi.fn(), editRequest: request("b", ask) }),
+ ));
+ });
+ const open = () => [...host.querySelectorAll("input")].map((input) => input.value);
+ await draw(null);
+ await draw({ botId: "a", nonce: 1 });
+ expect(open()).toEqual(["Atlas"]);
+ await act(async () => { host.querySelector("input")!.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); });
+ expect(open()).toEqual([]);
+ await draw({ botId: "b", nonce: 2 });
+ expect(open()).toEqual(["Birch"]);
+ await act(async () => { host.querySelector("input")!.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); });
+ await draw({ botId: "a", nonce: 3 });
+ expect(open()).toEqual(["Atlas"]);
+ await act(async () => root.unmount());
+ host.remove();
+});
diff --git a/src/components/RenameTitle.tsx b/src/components/RenameTitle.tsx
index b1fb8b8e30..3a9523e55c 100644
--- a/src/components/RenameTitle.tsx
+++ b/src/components/RenameTitle.tsx
@@ -45,6 +45,7 @@ export function RenameTitle({
useEffect(() => {
if (editRequest === handledRequest.current) return;
handledRequest.current = editRequest;
+ if (editRequest === 0) return;
setDraft(value);
setMode(true);
}, [editRequest]);