Skip to content

Commit 5aa1d99

Browse files
committed
fix: always return result array from useStableRows instead of stale fallback
The fallback path returned Array.from(prev.values()) which iterated the old map's insertion order rather than the current rows order. It also always created a new array, defeating the intended reference-reuse optimization. Returning result unconditionally is both correct and simpler.
1 parent 93552f6 commit 5aa1d99

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

apps/web/src/components/chat/MessagesTimeline.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
230230
// from TimelineRowCtx, which propagates through LegendList's memo.
231231
const renderItem = useCallback(
232232
({ item }: { item: MessagesTimelineRow }) => (
233-
<div
234-
className="mx-auto w-full min-w-0 max-w-3xl overflow-x-hidden"
235-
data-timeline-root="true"
236-
>
233+
<div className="mx-auto w-full min-w-0 max-w-3xl overflow-x-hidden" data-timeline-root="true">
237234
<TimelineRowContent row={item} />
238235
</div>
239236
),
@@ -402,9 +399,7 @@ function TimelineRowContent({ row }: { row: TimelineRow }) {
402399
<div className="my-3 flex items-center gap-3">
403400
<span className="h-px flex-1 bg-border" />
404401
<span className="rounded-full border border-border bg-background px-2.5 py-1 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/80">
405-
{ctx.completionSummary
406-
? `Response • ${ctx.completionSummary}`
407-
: "Response"}
402+
{ctx.completionSummary ? `Response • ${ctx.completionSummary}` : "Response"}
408403
</span>
409404
<span className="h-px flex-1 bg-border" />
410405
</div>
@@ -794,7 +789,6 @@ function useStableRows(rows: MessagesTimelineRow[]): MessagesTimelineRow[] {
794789
return useMemo(() => {
795790
const prev = prevById.current;
796791
const next = new Map<string, MessagesTimelineRow>();
797-
let anyChanged = false;
798792

799793
const result = rows.map((row) => {
800794
const prevRow = prev.get(row.id);
@@ -803,13 +797,11 @@ function useStableRows(rows: MessagesTimelineRow[]): MessagesTimelineRow[] {
803797
return prevRow;
804798
}
805799
next.set(row.id, row);
806-
anyChanged = true;
807800
return row;
808801
});
809802

810803
prevById.current = next;
811-
// If nothing changed and length matches, reuse the previous array reference
812-
return anyChanged || rows.length !== prev.size ? result : Array.from(prev.values());
804+
return result;
813805
}, [rows]);
814806
}
815807

0 commit comments

Comments
 (0)