Skip to content

Commit 2b07556

Browse files
fix(web): a stashed prompt ending in a skill or file chip restores as a chip (#28352)
1 parent 1e84887 commit 2b07556

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎apps/web/src/components/ChatView.browser.test.tsx‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ThreadId } from "@t3tools/contracts";
44
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
55
import type * as Context from "effect/Context";
66
import { expect, it, vi } from "vite-plus/test";
7-
import { page } from "vite-plus/test/browser";
7+
import { page, userEvent } from "vite-plus/test/browser";
88

99
import { AppRoot } from "~/AppRoot";
1010
// The route loads ChatView lazily, and its first transform (React Compiler over ~4k lines)
@@ -157,3 +157,37 @@ it("retains each thread's diff selection when returning from another thread or S
157157
turnId: a.runs[0]!.id,
158158
});
159159
});
160+
161+
it("a stashed prompt ending in a file chip restores with the chip", async () => {
162+
using _environment = installFakeEnvironment([]);
163+
__setClientSettingsForTests({
164+
...DEFAULT_CLIENT_SETTINGS,
165+
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
166+
});
167+
const draftId = DraftId.make("draft-28338");
168+
const drafts = useComposerDraftStore.getState();
169+
drafts.setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
170+
threadId: ThreadId.make("thread-28338"),
171+
});
172+
drafts.setPrompt(draftId, "Check [package.json](package.json) ");
173+
const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
174+
await router.load();
175+
await using _app = await render(<AppRoot router={router} />, {
176+
// AppRoot brings its own router.
177+
router: false,
178+
});
179+
const chip = page.getByRole("button", { name: "Preview package.json" });
180+
await expect.element(chip).toBeVisible();
181+
// The stash shortcut is a no-op until the shell snapshot lists the project.
182+
await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
183+
184+
const editor = page.getByTestId("composer-editor");
185+
await userEvent.click(editor);
186+
await userEvent.keyboard("{ControlOrMeta>}s{/ControlOrMeta}");
187+
await expect.element(chip).not.toBeInTheDocument();
188+
await userEvent.keyboard("{ControlOrMeta>}s{/ControlOrMeta}");
189+
190+
await vi.waitFor(() => expect(editor.element().textContent).toContain("Check"));
191+
expect(editor.element().textContent).not.toContain("[package.json](package.json)");
192+
await expect.element(chip).toBeVisible();
193+
});

‎apps/web/src/components/chat/useComposerStash.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { type PendingUserInput } from "../../session-logic";
2929
import { type ReviewCommentContext } from "../../reviewCommentContext";
3030
import { collapseExpandedComposerCursor } from "../../composer-logic";
31+
import { collectComposerPromptInlineTokens } from "../../composer-editor-mentions";
3132
import { compressImageForStash } from "../../lib/imageCompression";
3233
import { formatInlineContextReference } from "~/lib/composerContextReferences";
3334
import { isCommandPaletteOpen } from "../../commandPaletteBus";
@@ -469,7 +470,12 @@ export function useComposerStash(input: {
469470
return;
470471
}
471472
const replyTo = getComposerDraft(composerDraftTarget)?.replyTo;
472-
const prompt = promptRef.current.trim();
473+
const trimmedPrompt = promptRef.current.trim();
474+
// A trailing chip only parses with whitespace after it, so keep one space to restore it.
475+
const endsWithChip =
476+
collectComposerPromptInlineTokens(promptRef.current).at(-1)?.end ===
477+
promptRef.current.trimEnd().length;
478+
const prompt = endsWithChip ? `${trimmedPrompt} ` : trimmedPrompt;
473479
const attachmentDraft = readAttachmentDraft();
474480
const images = [...attachmentDraft.images];
475481
const files = [...attachmentDraft.files];

0 commit comments

Comments
 (0)