Skip to content

Commit 4953f59

Browse files
committed
perf(web): find lets go of the timeline it positioned once it has no match
It kept the entries until its next successful reveal, so a thread find was last used in stayed in memory after it was released.
1 parent 2237119 commit 4953f59

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,55 @@ describe("MessagesTimeline thread find", () => {
12211221
expect(top).toBeLessThan(bounds.bottom);
12221222
});
12231223
});
1224+
1225+
it("lets go of a timeline once find has no match in it", async () => {
1226+
setup();
1227+
const base = baseProps();
1228+
await using screen = await renderElement(
1229+
<MessagesTimeline {...base} timelineEntries={[message("Short thread")]} />,
1230+
);
1231+
// In its own function, so nothing in this test's frame holds the entries after the switch.
1232+
const revealMatch = async () => {
1233+
const replies = Array.from({ length: 40 }, (_, index) =>
1234+
message(
1235+
`${index === 5 ? "Needle here" : `Reply ${index}`}\n\n${"line\n\n".repeat(8)}`,
1236+
{ role: "assistant" },
1237+
`r-${index}`,
1238+
),
1239+
);
1240+
await screen.rerender(
1241+
<MessagesTimeline
1242+
{...base}
1243+
routeThreadKey="environment-local:thread-find-left"
1244+
timelineEntries={replies}
1245+
liveFollowEnabled={false}
1246+
findOpen
1247+
findExpanded
1248+
findQuery="Needle"
1249+
activeFindMatch={{ entryId: "entry-r-5", runId: null, occurrence: 0 }}
1250+
/>,
1251+
);
1252+
const viewport = base.listRef.current!.getScrollableNode()!;
1253+
await vi.waitFor(() => {
1254+
const row = screen.container.querySelector('[data-timeline-row-id="entry-r-5"]');
1255+
expect(row).not.toBeNull();
1256+
const bounds = viewport.getBoundingClientRect();
1257+
const top = row!.getBoundingClientRect().top;
1258+
expect(top).toBeGreaterThanOrEqual(bounds.top);
1259+
expect(top).toBeLessThan(bounds.bottom);
1260+
});
1261+
return new WeakRef(replies);
1262+
};
1263+
const shown = await revealMatch();
1264+
1265+
// Twice, because React keeps the previous render's props until the next render.
1266+
for (const text of ["Another thread", "Another thread, updated"]) {
1267+
await screen.rerender(<MessagesTimeline {...base} timelineEntries={[message(text)]} />);
1268+
}
1269+
await cdp().send("HeapProfiler.collectGarbage");
1270+
1271+
expect(shown.deref()).toBeUndefined();
1272+
});
12241273
});
12251274

12261275
describe("compact reasoning math", () => {

‎apps/web/src/components/chat/useThreadFindNavigation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function revealThreadFindMatch(
8686
state.settledMatch = null;
8787
state.revealedMatch = null;
8888
state.pagingPosition = null;
89+
state.positionedEntries = null;
8990
return;
9091
}
9192
const list = listRef.current;

0 commit comments

Comments
 (0)