The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the linked pull requests panel compiles without manual memoization (#20723)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:46 UTC
f29640d3e1369e08e35e4a7791f83ea652713cf4
1 file changed
+59
-65
apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+59
-65
@@ -16,7 +16,7 @@ import {
16
PlusIcon,
17
} from "lucide-react";
18
import { LegendList } from "@legendapp/list/react";
19
-import { memo, useCallback, useMemo, useState } from "react";
19
+import { memo, useState } from "react";
20
21
import {
22
COMPOSER_PULL_REQUEST_DRAG_TYPE,
@@ -100,13 +100,9 @@ function LinkRowImpl({
100
const openPrLink = useOpenPrLink(threadRef);
101
const [menuOpen, setMenuOpen] = useState(false);
102
const [menuPosition, setMenuPosition] = useState<{ x: number; y: number } | null>(null);
103
- const menuAnchor = useMemo(
104
- () =>
105
- menuPosition
106
- ? { getBoundingClientRect: () => new DOMRect(menuPosition.x, menuPosition.y, 0, 0) }
107
- : undefined,
108
- [menuPosition],
109
- );
103
+ const menuAnchor = menuPosition
104
+ ? { getBoundingClientRect: () => new DOMRect(menuPosition.x, menuPosition.y, 0, 0) }
105
+ : undefined;
106
const { link, depth, stack } = line;
107
const snapshot = link.snapshot;
108
const open = snapshot === null || snapshot.state === "open";
@@ -338,6 +334,26 @@ function LinkRowImpl({
334
/** Memoized so a modifier key or a sync of one link re-renders only the rows that changed. */
335
const LinkRow = memo(LinkRowImpl);
336
337
+// LegendList re-renders its rows when `data` changes identity. Inline, the compiler
338
+// recomputes these lines whenever a modifier key or row input changes too.
339
+function usePullRequestLines(
340
+ pullRequests: Parameters<typeof visibleThreadPullRequests>[0] | undefined,
341
+) {
342
+ "use memo";
343
+ const links = visibleThreadPullRequests(pullRequests ?? []);
344
+ const lines = pullRequestListLines(resolveThreadPullRequestChains(links));
345
+ return { links, lines };
346
+}
347
+
348
+function latestSyncedAt(links: ReadonlyArray<ThreadPullRequestLink>): string | null {
349
+ let latest: string | null = null;
350
+ for (const link of links) {
351
+ const at = link.snapshot?.syncedAt;
352
+ if (at !== undefined && (latest === null || at > latest)) latest = at;
353
+ }
354
+ return latest;
355
+}
356
+
357
const lineKey = (line: PullRequestListLine) =>
358
`${line.link.host}/${line.link.repository}#${line.link.number}`;
359
@@ -357,73 +373,51 @@ export function ThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
373
function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThreadRef }) {
374
const thread = useThreadShell(threadRef);
375
const projects = useProjects();
360
- const environmentProjects = useMemo(
361
- () =>
362
- projects
363
- .filter((project) => project.environmentId === threadRef.environmentId)
364
- .toSorted((left, right) =>
365
- left.id === thread?.projectId ? -1 : right.id === thread?.projectId ? 1 : 0,
366
- ),
367
- [projects, threadRef.environmentId, thread?.projectId],
368
- );
376
+ const environmentProjects = projects
377
+ .filter((project) => project.environmentId === threadRef.environmentId)
378
+ .toSorted((left, right) =>
379
+ left.id === thread?.projectId ? -1 : right.id === thread?.projectId ? 1 : 0,
380
+ );
381
const modifiers = useShortcutModifierState(true);
382
const speedMode =
383
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
372
- const openLinkDialog = useCallback(() => openLinkPullRequestDialog(threadRef), [threadRef]);
384
+ const openLinkDialog = () => openLinkPullRequestDialog(threadRef);
385
const unlink = useAtomCommand(threadEnvironment.unlinkPullRequest, { reportFailure: true });
386
const watch = useAtomCommand(threadEnvironment.watchPullRequest, { reportFailure: true });
387
const capabilities = useServerConfigs().get(threadRef.environmentId)?.environment.capabilities;
388
const supportsWatch = capabilities?.threadPullRequestWatch === true;
377
- const links = useMemo(() => visibleThreadPullRequests(thread?.pullRequests ?? []), [thread]);
378
- const lines = useMemo(() => pullRequestListLines(resolveThreadPullRequestChains(links)), [links]);
379
- const handleUnlink = useCallback(
380
- (link: ThreadPullRequestLink) => {
381
- void unlink({
382
- environmentId: threadRef.environmentId,
383
- input: {
384
- threadId: threadRef.threadId,
385
- host: link.host,
386
- repository: link.repository,
387
- number: link.number,
388
- },
389
- });
390
- },
391
- [threadRef, unlink],
392
- );
393
- const handleSetWatching = useCallback(
394
- (link: ThreadPullRequestLink, watching: boolean) => {
395
- void watch({
396
- environmentId: threadRef.environmentId,
397
- input: {
398
- threadId: threadRef.threadId,
399
- host: link.host,
400
- repository: link.repository,
401
- number: link.number,
402
- watching,
403
- },
404
- });
405
- },
406
- [threadRef, watch],
407
- );
408
- const openCount = useMemo(
409
- () => links.filter((link) => link.snapshot === null || link.snapshot.state === "open").length,
410
- [links],
411
- );
412
- const lastSynced = useMemo(() => {
413
- let latest: string | null = null;
414
- for (const link of links) {
415
- const at = link.snapshot?.syncedAt;
416
- if (at !== undefined && (latest === null || at > latest)) latest = at;
417
- }
418
- return latest;
419
- }, [links]);
389
+ const { links, lines } = usePullRequestLines(thread?.pullRequests);
390
+ const handleUnlink = (link: ThreadPullRequestLink) => {
391
+ void unlink({
392
+ environmentId: threadRef.environmentId,
393
+ input: {
394
+ threadId: threadRef.threadId,
395
+ host: link.host,
396
+ repository: link.repository,
397
+ number: link.number,
398
+ },
399
+ });
400
+ };
401
+ const handleSetWatching = (link: ThreadPullRequestLink, watching: boolean) => {
402
+ void watch({
403
+ environmentId: threadRef.environmentId,
404
+ input: {
405
+ threadId: threadRef.threadId,
406
+ host: link.host,
407
+ repository: link.repository,
408
+ number: link.number,
409
+ watching,
410
+ },
411
+ });
412
+ };
413
+ const openCount = links.filter(
414
+ (link) => link.snapshot === null || link.snapshot.state === "open",
415
+ ).length;
416
+ const lastSynced = latestSyncedAt(links);
417
418
// Legend re-renders visible rows only when data or extraData changes, so everything the rows
419
// read from outside their line goes in here.
423
- const rowInputs = useMemo(
424
- () => ({ speedMode, environmentProjects, capabilities, supportsWatch, thread }),
425
- [speedMode, environmentProjects, capabilities, supportsWatch, thread],
426
- );
420
+ const rowInputs = { speedMode, environmentProjects, capabilities, supportsWatch, thread };
421
422
if (links.length === 0) {
423
return (