File tree Expand file tree Collapse file tree
apps/web/src/components/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import { Link , useNavigate } from "@tanstack/react-router" ;
77import { ArrowUpRightIcon , PencilIcon , QuoteIcon } from "lucide-react" ;
88import {
9+ useCallback ,
910 useEffect ,
1011 useEffectEvent ,
1112 useRef ,
@@ -243,19 +244,22 @@ export function AssistantCitationChip({
243244
244245function 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" ,
You can’t perform that action at this time.
0 commit comments