Skip to content

Commit 6764399

Browse files
committed
Fix rerender audit regressions
1 parent 3137cc4 commit 6764399

4 files changed

Lines changed: 47 additions & 17 deletions

File tree

apps/web/src/components/DiffPanel.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,18 @@ const DiffPanelContent = memo(function DiffPanelContent(props: {
423423
} = props;
424424
const { resolvedTheme } = useTheme();
425425
const patchViewportRef = useRef<HTMLDivElement>(null);
426+
const activeProject = useStore((store) =>
427+
workspaceSnapshot
428+
? selectProjectByRef(store, {
429+
environmentId: workspaceSnapshot.environmentId,
430+
projectId: workspaceSnapshot.projectId,
431+
})
432+
: undefined,
433+
);
434+
const activeCwd = workspaceSnapshot?.worktreePath ?? activeProject?.cwd ?? null;
426435
const isGitRepo = useGitStatusIsRepo({
427436
environmentId: workspaceSnapshot?.environmentId ?? null,
428-
cwd: workspaceSnapshot?.worktreePath ?? null,
437+
cwd: activeCwd,
429438
});
430439
const { inferredCheckpointTurnCountByTurnId } = useTurnDiffSummaries(orderedTurnDiffSummaries);
431440
const activeCheckpointSelection = useMemo(() => {
@@ -475,15 +484,6 @@ const DiffPanelContent = memo(function DiffPanelContent(props: {
475484
activeCheckpointRange: selectedTurn ? selectedCheckpointRange : conversationCheckpointRange,
476485
};
477486
}, [inferredCheckpointTurnCountByTurnId, orderedTurnDiffSummaries, selectedTurnId]);
478-
const activeProject = useStore((store) =>
479-
workspaceSnapshot
480-
? selectProjectByRef(store, {
481-
environmentId: workspaceSnapshot.environmentId,
482-
projectId: workspaceSnapshot.projectId,
483-
})
484-
: undefined,
485-
);
486-
const activeCwd = workspaceSnapshot?.worktreePath ?? activeProject?.cwd;
487487
const activeCheckpointDiffQuery = useQuery(
488488
checkpointDiffQueryOptions({
489489
environmentId: workspaceSnapshot?.environmentId ?? null,

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export const HistoricalMessagesTimelineSection = memo(function HistoricalMessage
191191
[historicalTimelineEntries],
192192
);
193193
const historicalRows = useStableTimelineRows(historicalRawRows);
194+
const shouldRenderHistoricalRowsWithoutVirtualizer = typeof ResizeObserver === "undefined";
194195

195196
const virtualizedRowCount = clamp(historicalRows.length, {
196197
minimum: 0,
@@ -348,15 +349,20 @@ export const HistoricalMessagesTimelineSection = memo(function HistoricalMessage
348349

349350
return (
350351
<div ref={timelineRootRef} data-timeline-root="true" className="w-full overflow-x-hidden">
351-
{virtualizedRowCount > 0 && (
352+
{shouldRenderHistoricalRowsWithoutVirtualizer ? (
353+
<NonVirtualTimelineRows
354+
rows={historicalRows}
355+
renderRowContent={renderHistoricalRowContent}
356+
/>
357+
) : virtualizedRowCount > 0 ? (
352358
<HistoricalTimelineRows
353359
rows={historicalRows}
354360
virtualRows={virtualRows}
355361
totalSize={rowVirtualizer.getTotalSize()}
356362
measureElement={rowVirtualizer.measureElement}
357363
renderRowContent={renderHistoricalRowContent}
358364
/>
359-
)}
365+
) : null}
360366
</div>
361367
);
362368
});
@@ -593,6 +599,13 @@ const HistoricalTimelineRows = memo(function HistoricalTimelineRows(props: {
593599
const LiveTimelineRows = memo(function LiveTimelineRows(props: {
594600
rows: ReadonlyArray<TimelineRow>;
595601
renderRowContent: (row: TimelineRow) => ReactNode;
602+
}) {
603+
return <NonVirtualTimelineRows rows={props.rows} renderRowContent={props.renderRowContent} />;
604+
});
605+
606+
const NonVirtualTimelineRows = memo(function NonVirtualTimelineRows(props: {
607+
rows: ReadonlyArray<TimelineRow>;
608+
renderRowContent: (row: TimelineRow) => ReactNode;
596609
}) {
597610
return props.rows.map((row) => (
598611
<div key={`non-virtual-row:${row.id}`}>{props.renderRowContent(row)}</div>

apps/web/src/lib/providerReactQuery.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,28 @@ describe("checkpointDiffQueryOptions", () => {
141141
expect(retry(3, new Error("Something else failed."))).toBe(false);
142142
});
143143

144+
it("retries transient checkpoint errors for full thread diffs too", () => {
145+
const options = checkpointDiffQueryOptions({
146+
environmentId,
147+
threadId,
148+
fromTurnCount: 0,
149+
toTurnCount: 2,
150+
cacheScope: "thread:all",
151+
});
152+
const retry = options.retry;
153+
expect(typeof retry).toBe("function");
154+
if (typeof retry !== "function") {
155+
throw new Error("Expected retry to be a function.");
156+
}
157+
158+
expect(
159+
retry(1, new Error("Filesystem checkpoint is unavailable for turn 2 in thread thread-1.")),
160+
).toBe(true);
161+
expect(
162+
retry(12, new Error("Filesystem checkpoint is unavailable for turn 2 in thread thread-1.")),
163+
).toBe(false);
164+
});
165+
144166
it("backs off longer for checkpoint-not-ready errors", () => {
145167
const options = checkpointDiffQueryOptions({
146168
environmentId,

apps/web/src/lib/providerReactQuery.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ function isCheckpointTemporarilyUnavailable(error: unknown): boolean {
9494

9595
export function checkpointDiffQueryOptions(input: CheckpointDiffQueryInput) {
9696
const decodedRequest = decodeCheckpointDiffRequest(input);
97-
const isFullThreadDiffRequest =
98-
decodedRequest._tag === "Some" && decodedRequest.value.kind === "fullThreadDiff";
9997

10098
return queryOptions({
10199
queryKey: providerQueryKeys.checkpointDiff(input),
@@ -120,9 +118,6 @@ export function checkpointDiffQueryOptions(input: CheckpointDiffQueryInput) {
120118
decodedRequest._tag === "Some",
121119
staleTime: Infinity,
122120
retry: (failureCount, error) => {
123-
if (isFullThreadDiffRequest) {
124-
return false;
125-
}
126121
if (isCheckpointTemporarilyUnavailable(error)) {
127122
return failureCount < 12;
128123
}

0 commit comments

Comments
 (0)