The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the assistant citation target hook compiles with the React Compiler (#20614)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:01 UTC
3f60d4d380cb29606614077cb54a709011e0901c
1 file changed
+10
-5
apps/web/src/components/chat/useAssistantCitationTarget.ts
+10
-5
@@ -1,6 +1,6 @@
1
import type { LegendListRef } from "@legendapp/list/react";
2
import type { RunId } from "@t3tools/contracts";
3
-import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
3
+import { useEffect, useRef, useState, type RefObject } from "react";
4
import type { TimelineEntry } from "../../session-logic";
5
import type { MessagesTimelineRow } from "./MessagesTimeline.logic";
6
import type { AssistantCitationRequest, AssistantCitationTarget } from "./AssistantCitationSource";
@@ -36,13 +36,21 @@ export function useAssistantCitationTarget({
36
const [ready, setReady] = useState<AssistantCitationTarget | null>(null);
37
const [finishedKey, setFinishedKey] = useState<string | null>(null);
38
const [listLoaded, setListLoaded] = useState(false);
39
- const onListLoad = useCallback(() => setListLoaded(true), []);
39
+ const onListLoad = () => setListLoaded(true);
40
const navigationRef = useRef<{
41
target: AssistantCitationTarget;
42
requestedPages: Set<string>;
43
done: boolean;
44
} | null>(null);
45
46
+ // A target belongs to one request, so returning to an earlier key never reuses it.
47
+ if (ready !== null && ready.key !== request?.key) {
48
+ setReady(null);
49
+ }
50
+ if (!request && finishedKey !== null) {
51
+ setFinishedKey(null);
52
+ }
53
+
54
useEffect(() => {
55
if (navigationRef.current && navigationRef.current.target.key !== request?.key) {
56
navigationRef.current.target.activationRef.current.dismissed = true;
@@ -50,8 +58,6 @@ export function useAssistantCitationTarget({
58
}
59
if (!request) {
60
navigationRef.current = null;
53
- setReady(null);
54
- setFinishedKey(null);
61
return;
62
}
63
if (navigationRef.current?.target.key !== request.key) {
@@ -71,7 +77,6 @@ export function useAssistantCitationTarget({
77
requestedPages: new Set(),
78
done: false,
79
};
74
- setReady(null);
80
onManualNavigation();
81
}
82
if (!viewport || historyLoading) return;