@devries-cameron20 / t3code Mirror · read-only / commits / b3d05640a4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 05:30 UTC

refactor(web): the thread pull requests panel keeps its caching without "use memo" hooks (#20740)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 23:18 UTC b3d05640a4670bd34ec4950d2a60f0616dea6780
1 file changed +14 -19
apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+14 -19
@@ -334,17 +334,6 @@ 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 -
337 function latestSyncedAt(links: ReadonlyArray<ThreadPullRequestLink>): string | null {
338 let latest: string | null = null;
339 for (const link of links) {
@@ -378,6 +367,17 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
367 .toSorted((left, right) =>
368 left.id === thread?.projectId ? -1 : right.id === thread?.projectId ? 1 : 0,
369 );
370 + // LegendList re-renders its rows when `data` changes identity. `links` and values derived
371 + // from it go through plain functions only here, before the next hook, so the compiler keeps
372 + // `lines` in its own cache scope.
373 + const links = visibleThreadPullRequests(thread?.pullRequests ?? []);
374 + const lines = pullRequestListLines(resolveThreadPullRequestChains(links));
375 + const openCount = links.filter(
376 + (link) => link.snapshot === null || link.snapshot.state === "open",
377 + ).length;
378 + const lastSynced = latestSyncedAt(links);
379 + const syncedLabel = lastSynced ? ` · synced ${formatRelativeTimeLabel(lastSynced)}` : "";
380 + const linkCount = links.length;
381 const modifiers = useShortcutModifierState(true);
382 const speedMode =
383 modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
@@ -386,7 +386,6 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
386 const watch = useAtomCommand(threadEnvironment.watchPullRequest, { reportFailure: true });
387 const capabilities = useServerConfigs().get(threadRef.environmentId)?.environment.capabilities;
388 const supportsWatch = capabilities?.threadPullRequestWatch === true;
389 - const { links, lines } = usePullRequestLines(thread?.pullRequests);
389 const handleUnlink = (link: ThreadPullRequestLink) => {
390 void unlink({
391 environmentId: threadRef.environmentId,
@@ -410,16 +409,12 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
409 },
410 });
411 };
413 - const openCount = links.filter(
414 - (link) => link.snapshot === null || link.snapshot.state === "open",
415 - ).length;
416 - const lastSynced = latestSyncedAt(links);
412
413 // Legend re-renders visible rows only when data or extraData changes, so everything the rows
414 // read from outside their line goes in here.
415 const rowInputs = { speedMode, environmentProjects, capabilities, supportsWatch, thread };
416
422 - if (links.length === 0) {
417 + if (linkCount === 0) {
418 return (
419 <div className="flex h-full flex-col items-center justify-center gap-2 p-6 text-center">
420 <PullRequestGlyph.link aria-hidden className="size-6 text-muted-foreground/60" />
@@ -466,8 +461,8 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
461 />
462 <footer className="flex items-center justify-between border-t border-border/60 px-2 py-1.5 text-2xs text-muted-foreground">
463 <span>
469 - {openCount} open · {links.length} linked
470 - {lastSynced ? ` · synced ${formatRelativeTimeLabel(lastSynced)}` : ""}
464 + {openCount} open · {linkCount} linked
465 + {syncedLabel}
466 </span>
467 <Button size="xs" variant="ghost" onClick={openLinkDialog}>
468 <PlusIcon className="size-3.5" />