Skip to content

Commit a0056dd

Browse files
Yuruzuuclaude
andauthored
perf(web): switching threads no longer re-renders every sidebar row (pingdotgg#29150)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 739aba7 commit a0056dd

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
22412241
threadKey,
22422242
currentThreadKey: readRouteThreadKey(router),
22432243
action: "snooze",
2244-
// oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
22452244
now: new Date().toISOString(),
22462245
thread: readThreadShell(threadRef),
22472246
})
@@ -2250,26 +2249,28 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
22502249
}
22512250
return { status: "success" } as const;
22522251
};
2253-
const attemptSnooze = (
2254-
threadRef: ScopedThreadRef,
2255-
preset: Pick<SnoozePreset, "snoozedUntil">,
2256-
opts: { coSnoozingKeys?: ReadonlySet<string> } = {},
2257-
) => {
2258-
void (async () => {
2259-
const outcome = await performSnooze(threadRef, preset, opts);
2260-
if (outcome.status === "failure") {
2261-
toastManager.add(
2262-
stackedThreadToast({
2263-
type: "error",
2264-
title: "Failed to snooze thread",
2265-
description:
2266-
outcome.error instanceof Error ? outcome.error.message : "An error occurred.",
2267-
}),
2268-
);
2269-
return;
2270-
}
2271-
})();
2272-
};
2252+
const attemptSnooze = useStableCallback(
2253+
(
2254+
threadRef: ScopedThreadRef,
2255+
preset: Pick<SnoozePreset, "snoozedUntil">,
2256+
opts: { coSnoozingKeys?: ReadonlySet<string> } = {},
2257+
) => {
2258+
void (async () => {
2259+
const outcome = await performSnooze(threadRef, preset, opts);
2260+
if (outcome.status === "failure") {
2261+
toastManager.add(
2262+
stackedThreadToast({
2263+
type: "error",
2264+
title: "Failed to snooze thread",
2265+
description:
2266+
outcome.error instanceof Error ? outcome.error.message : "An error occurred.",
2267+
}),
2268+
);
2269+
return;
2270+
}
2271+
})();
2272+
},
2273+
);
22732274

22742275
const handleMultiSelectContextMenu = useStableCallback(
22752276
async (position: { x: number; y: number }) => {
@@ -2281,7 +2282,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
22812282
);
22822283
if (threadKeys.length === 0) return;
22832284
const count = threadKeys.length;
2284-
// oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
22852285
const selectionNow = new Date();
22862286
const selectedThreads = threadKeys.flatMap((threadKey) => {
22872287
const thread = threadByKeyRef.current.get(threadKey);
@@ -2312,7 +2312,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
23122312
pinnedCount: pinnedSelectedThreads.length,
23132313
});
23142314
// Presets sync across environments, so the first selected thread's stand for all.
2315-
// oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
23162315
const menuOpenedAt = new Date();
23172316
const snoozePresets = resolveSnoozePresets(
23182317
menuOpenedAt,

‎apps/web/test/appScenarios.renders.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ it("app-switch-thread", async () => {
278278
);
279279
await expect.element(lastAnswer(threadId)).toBeVisible();
280280
};
281-
await report("app-switch-thread", [await measure(go(B)), await measure(go(A))]);
281+
const windows = [await measure(go(B)), await measure(go(A))];
282+
// Only the rows losing and gaining the active highlight change.
283+
for (const window of windows) expect(window.components.SidebarThreadRow).toBe(2);
284+
await report("app-switch-thread", windows);
282285
});
283286

284287
// Through the diff.toggle shortcut, the same handler as the header's diff button.

0 commit comments

Comments
 (0)