From 8a1e2d1d604a2f5c4d614763c9e9d90f3fed576f Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 11 Sep 2026 11:45:51 +0100 Subject: [PATCH] fix(upload): select the uploaded source by its own id The chat selection was inferred by diffing the refreshed source list against the snapshot taken before the upload, so any source that appeared meanwhile -- another upload finishing, a new team share -- could be picked instead. The upload response already carries the id; match on it, and select nothing when it is absent rather than guessing. Drops the now-unused sourceDocs read and its stale dependency. --- frontend/src/upload/Upload.tsx | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index fe6a22cd..2c0858a5 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -27,7 +27,6 @@ import { ActiveState, Doc } from '../models/misc'; import { getDocs } from '../preferences/preferenceApi'; import { selectSelectedDocs, - selectSourceDocs, selectToken, setSelectedDocs, setSourceDocs, @@ -411,8 +410,6 @@ function Upload({ heading: schema.heading, })); - const sourceDocs = useSelector(selectSourceDocs); - const resetUploaderState = useCallback(() => { setIngestor({ type: null, name: '', config: {} }); setfiles([]); @@ -485,15 +482,11 @@ function Upload({ if (status !== 'completed') return; refreshSourceDocs() .then((docs) => { - if (selectUploadedDoc && Array.isArray(docs)) { - const existingDocIds = new Set( - (Array.isArray(sourceDocs) ? sourceDocs : []) - .map((doc: Doc) => doc?.id) - .filter((id): id is string => Boolean(id)), - ); - const newDoc = docs.find( - (doc: Doc) => doc.id && !existingDocIds.has(doc.id), - ); + if (selectUploadedDoc && Array.isArray(docs) && sourceId) { + // Match the id this upload returned. Diffing against the list as + // it looked before would pick up any source that appeared + // meanwhile — another upload finishing, or a new team share. + const newDoc = docs.find((doc: Doc) => doc.id === sourceId); if (newDoc) { // If only one doc is selected, replace it completely // If multiple docs are selected, append the new doc @@ -578,7 +571,6 @@ function Upload({ refreshSourceDocs, selectedDocs, selectUploadedDoc, - sourceDocs, store, ], );