Skip to content

Commit 943287b

Browse files
committed
fix(web): a stale chip media lookup no longer replaces a newer preview
The media request is now claimed at click time, before the file lookup, so a later click or a thread switch during the lookup drops the older open.
1 parent 2fd47ab commit 943287b

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,10 +2713,15 @@ function useChatMarkdownState({
27132713
onOpenInPanel={openFileInPanel}
27142714
onOpenMedia={
27152715
threadRef && canPreviewMedia
2716-
? () =>
2717-
void resolveLink().then((resolved) =>
2718-
openMarkdownMedia(mediaPath, resolved.filePath),
2719-
)
2716+
? () => {
2717+
// Claim the request before the lookup, so a later click or a
2718+
// thread switch during it drops this open.
2719+
const requestId = ++mediaRequestId.current;
2720+
void resolveLink().then((resolved) => {
2721+
if (mediaRequestId.current !== requestId) return;
2722+
openMarkdownMedia(mediaPath, resolved.filePath);
2723+
});
2724+
}
27202725
: undefined
27212726
}
27222727
openInEditorMenuLabel={preferredEditorMenuLabel}

0 commit comments

Comments
 (0)