Skip to content

Commit ef88e90

Browse files
fix(web): pasted duplicates keep their chip when the draft holds them under an alias
A pasted record that matches a draft record found under its kind-scoped id was skipped without a rewrite, so the paste turned its reference into a label. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 809724e commit ef88e90

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎apps/web/src/components/chat/useComposerContextImport.browser.test.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,28 @@ it("imports a pasted thread from a machine this one does not link to as its tran
274274
expect(store.getComposerDraft(target)?.threadContexts ?? []).toEqual([]);
275275
});
276276

277+
it("points a pasted duplicate at the id the draft holds it under", async () => {
278+
const target = DraftId.make("clipboard-alias-duplicate");
279+
const held = threadContextRecord(
280+
{ environmentId: EnvironmentId.make("clipboard-target"), threadId: ThreadId.make("alias") },
281+
"Alias thread",
282+
);
283+
const pasted = { ...held, contextId: ComposerContextId.make("alias") };
284+
let importer!: Importer;
285+
await using _screen = await render(
286+
<Harness
287+
input={{
288+
...importInput(target, { current: "" }),
289+
composerContextRecords: new Map([[held.contextId, { kind: "thread", record: held }]]),
290+
}}
291+
ready={(value) => {
292+
importer = value;
293+
}}
294+
/>,
295+
);
296+
expect(importer.importContextRecords([pasted], null).get("alias")).toBe(held.contextId);
297+
});
298+
277299
// A stash restores into the prompt behind an open question, not into the question's answer.
278300
it("imports a restored thread's transcript into the draft the restore names", async () => {
279301
const target = DraftId.make("stash-unlinked-thread");

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,13 @@ export function useComposerContextImport(input: {
322322
const record = asKnownContextRecord(candidate);
323323
if (!record) continue;
324324
// A reminted annotation needs its screenshot under the new annotation id.
325-
const existing = dependentAttachmentLocalIds.has(record.contextId)
325+
const existingId = dependentAttachmentLocalIds.has(record.contextId)
326326
? undefined
327-
: composerContextImportLookupIds(record).flatMap((contextId) => {
328-
const found = composerContextRecords.get(contextId);
329-
return found ? [found] : [];
330-
})[0];
327+
: composerContextImportLookupIds(record).find((contextId) =>
328+
composerContextRecords.has(contextId),
329+
);
330+
const existing =
331+
existingId === undefined ? undefined : composerContextRecords.get(existingId);
331332
// Upload completion can change the server id since copy; the local bytes still match.
332333
if (
333334
sourceEnvironmentId !== null &&
@@ -336,8 +337,10 @@ export function useComposerContextImport(input: {
336337
existing.record.file !== null &&
337338
existing.record.file ===
338339
copiedComposerAttachmentFile(sourceEnvironmentId, record.attachmentId)
339-
)
340+
) {
341+
rewritten.set(record.contextId, existingId ?? record.contextId);
340342
continue;
343+
}
341344
const existingRecord =
342345
existing?.kind === "terminal"
343346
? terminalContextRecord(existing.record)
@@ -364,6 +367,8 @@ export function useComposerContextImport(input: {
364367
if (record.kind === "preview-annotation" && record.screenshotContextId) {
365368
skippedDependentAttachmentIds.add(record.screenshotContextId);
366369
}
370+
// The draft may hold the record under its kind-scoped alias.
371+
rewritten.set(record.contextId, existingId ?? record.contextId);
367372
continue;
368373
}
369374
const conflicts = existing !== undefined;

0 commit comments

Comments
 (0)