Skip to content

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

fix(composer): /fork is not offered in a blank new chat

Absterrg03c5faad47e9e
diff --git a/src/components/Composer.slash.test.ts b/src/components/Composer.slash.test.ts
index 4e40fd201b..e1867cbd37 100644
--- a/src/components/Composer.slash.test.ts
+++ b/src/components/Composer.slash.test.ts
@@ -6,6 +6,7 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { Bot } from "@/state/store";
import { restoreComposerDraft } from "@/lib/drafts";
+import { newChatThreadId } from "@/state/new-chat";
const dispatch = vi.hoisted(() => vi.fn());
const ENGINE = "claude-3f0c2b1e-9d1a-4c55-8a51-0a3a6f1e2b7c";
@@ -60,8 +61,8 @@ describe("the / menu in the composer", () => {
vi.unstubAllGlobals();
});
- function fill(text: string, caret = text.length) {
- flushSync(() => restoreComposerDraft(draftId, { text, attachments: [] }));
+ function fill(text: string, caret = text.length, draft = draftId) {
+ flushSync(() => restoreComposerDraft(draft, { text, attachments: [] }));
const input = container.querySelector("textarea")!;
input.setSelectionRange(caret, caret);
flushSync(() => input.dispatchEvent(new KeyboardEvent("keyup", { key: "/", bubbles: true })));
@@ -88,6 +89,18 @@ describe("the / menu in the composer", () => {
expect(input.value).toBe("");
});
+ it("offers no /fork in a blank new chat, which has no thread to fork yet", () => {
+ const blank = newChatThreadId(bot.id);
+ const blankDraft = `bot:${bot.id}:${blank}`;
+ flushSync(() => root.render(createElement(Composer, { bot: { ...bot, threadId: blank } })));
+ fill("/", 1, blankDraft);
+ expect(labels()).toEqual(["/goal", "/learn", "/setup", "/burst", "/fork-release", "/standup"]);
+ const input = fill("/fork", 5, blankDraft);
+ press(input, "Enter");
+ expect(dispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: "forkMessage" }));
+ restoreComposerDraft(blankDraft, { text: "", attachments: [] });
+ });
+
it("chooses the highlighted skill when it also matches a complete /fork", () => {
const input = fill("/fork");
press(input, "ArrowDown");
diff --git a/src/components/Composer.tsx b/src/components/Composer.tsx
index 27ae7d0a24..e246d88a92 100644
--- a/src/components/Composer.tsx
+++ b/src/components/Composer.tsx
@@ -2,6 +2,7 @@ import { directMessageSent, roomMessageSent } from "@/lib/product-events";
import { TeamAudienceLabel } from "./TeamSideSwitch";
import { useComposerDictation } from "@/lib/use-composer-dictation";
import { ComposerForkError, useComposerFork } from "./ComposerFork";
+import { isNewChatThread } from "@/state/new-chat";
import { useCallback, useEffect, useMemo, useRef, useState, type SetStateAction } from "react";
import { Mic, Square } from "lucide-react";
import { sameFields, useStoreDispatch, useStoreSelector } from "@/state/store-select"; import { useStoreRef } from "@/state/store-ref"; import { sameDrawnBots } from "@/lib/drawn-bots";
@@ -178,7 +179,7 @@ export function Composer({
draftId,
!group && bot && !state.config?.team ? `bot:${bot.id}` : undefined,
);
- const forkOwnerId = singleRow || group?.dm || !threadId ? undefined : group?.id ?? bot?.id;
+ const forkOwnerId = singleRow || group?.dm || !threadId || isNewChatThread(threadId) ? undefined : group?.id ?? bot?.id;
const attachmentPending = useDraftAttachmentPending(draftId);
const failedSends = useFailedComposerSends(draftId); const picks = mentionPicksFor(draftId);
const [channelMode, setChannelMode] = useComposerChannelMode(draftId);