Skip to content

Commit 848a31d

Browse files
committed
fix(web): guard stale markdown file lookups
1 parent 8e356f1 commit 848a31d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,31 +2671,40 @@ function useChatMarkdownState({
26712671
);
26722672
const openMarkdownFileInEditor = useCallback(
26732673
async (fileLinkMeta: MarkdownFileLinkMeta) => {
2674+
const isLatestLookup = threadRef
2675+
? claimWorkspaceBasenameLookup(scopedThreadKey(threadRef))
2676+
: () => true;
26742677
const workspaceRelativePath = fileLinkMeta.workspaceRelativePath;
26752678
const match = workspaceRelativePath
26762679
? await findWorkspaceBasenameMatch(workspaceRelativePath)
26772680
: null;
2681+
if (!isLatestLookup()) return AsyncResult.success(undefined);
26782682
if (!match || !cwd) {
26792683
return openInPreferredEditor(fileLinkMeta.targetPath);
26802684
}
26812685
const withPosition = fileLinkMeta.line
26822686
? `${match}:${fileLinkMeta.line}${fileLinkMeta.column ? `:${fileLinkMeta.column}` : ""}`
26832687
: match;
2688+
if (!isLatestLookup()) return AsyncResult.success(undefined);
26842689
return openInPreferredEditor(resolvePathLinkTarget(withPosition, cwd));
26852690
},
2686-
[cwd, findWorkspaceBasenameMatch, openInPreferredEditor],
2691+
[cwd, findWorkspaceBasenameMatch, openInPreferredEditor, threadRef],
26872692
);
26882693
const openMarkdownFileInBrowser = useCallback(
26892694
async (fileLinkMeta: MarkdownFileLinkMeta) => {
2695+
const isLatestLookup = threadRef
2696+
? claimWorkspaceBasenameLookup(scopedThreadKey(threadRef))
2697+
: () => true;
26902698
const workspaceRelativePath = fileLinkMeta.workspaceRelativePath;
26912699
const match = workspaceRelativePath
26922700
? await findWorkspaceBasenameMatch(workspaceRelativePath)
26932701
: null;
2702+
if (!isLatestLookup()) return AsyncResult.success(undefined);
26942703
return openMarkdownFileInPreview(
26952704
match && cwd ? resolvePathLinkTarget(match, cwd) : fileLinkMeta.filePath,
26962705
);
26972706
},
2698-
[cwd, findWorkspaceBasenameMatch, openMarkdownFileInPreview],
2707+
[cwd, findWorkspaceBasenameMatch, openMarkdownFileInPreview, threadRef],
26992708
);
27002709
const fileLinkChip = useCallback(
27012710
(fileLinkMeta: MarkdownFileLinkMeta, copyMarkdown: string, mediaSource?: string) => {

0 commit comments

Comments
 (0)