Skip to content

Commit aa7e70c

Browse files
committed
fix(web): citation quote keeps one resize subscription across fade updates
1 parent f43a19d commit aa7e70c

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎apps/web/src/components/chat/AssistantCitationChip.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { Link, useNavigate } from "@tanstack/react-router";
77
import { ArrowUpRightIcon, PencilIcon, QuoteIcon } from "lucide-react";
88
import {
9+
useCallback,
910
useEffect,
1011
useEffectEvent,
1112
useRef,
@@ -243,19 +244,22 @@ export function AssistantCitationChip({
243244

244245
function AssistantCitationQuote({ citation }: { citation: AssistantCitation }) {
245246
const [fade, setFade] = useState({ top: false, bottom: false });
246-
const updateFade = (element: HTMLElement) => {
247+
const updateFade = useCallback((element: HTMLElement) => {
247248
const top = element.scrollTop > 1;
248249
const bottom = element.scrollHeight - element.clientHeight - element.scrollTop > 1;
249250
setFade((current) =>
250251
current.top === top && current.bottom === bottom ? current : { top, bottom },
251252
);
252-
};
253+
}, []);
254+
// Stable so a fade update during resize delivery does not resubscribe the element.
255+
const observeFade = useCallback(
256+
(element: HTMLDivElement | null) =>
257+
element ? observeResize(element, () => updateFade(element)) : undefined,
258+
[updateFade],
259+
);
253260
return (
254261
<div
255-
ref={(element) => {
256-
if (!element) return;
257-
return observeResize(element, () => updateFade(element));
258-
}}
262+
ref={observeFade}
259263
onScroll={(event) => updateFade(event.currentTarget)}
260264
className={cn(
261265
"max-h-64 min-h-0 space-y-3 self-stretch overflow-y-auto whitespace-pre-wrap wrap-break-word",

0 commit comments

Comments
 (0)