@devries-cameron20 / t3code-1 / commits / 4dd6a65abe
Fork 0

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

refactor(web): the pull request detail panel keeps its caching with fewer "use memo" hooks (#20761)

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

Julius Marminge committed Oct 16, 2026 at 23:22 UTC 4dd6a65abe62f570b80725826b67e1763093140a
1 file changed +22 -26
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+22 -26
@@ -386,13 +386,11 @@ function reportCheckoutCommandError(error: Error) {
386 });
387 }
388
389 -function useResolvedPullRequestReference(
389 +function resolvePullRequestReference(
390 requestedReference: PullRequestRef,
391 repositoryIdentity: Parameters<typeof resolvePullRequestReferenceHost>[1],
392 supportsThreadPullRequests: boolean,
393 ): PullRequestRef {
394 - // Calls no hooks, so the compiler needs the directive to memoize it.
395 - "use memo";
394 return supportsThreadPullRequests
395 ? resolvePullRequestReferenceHost(requestedReference, repositoryIdentity)
396 : {
@@ -402,9 +400,7 @@ function useResolvedPullRequestReference(
400 };
401 }
402
405 -function usePullRequestDetailSummary(data: PullRequestDetail | null) {
406 - // Calls no hooks, so the compiler needs the directive to memoize it.
407 - "use memo";
403 +function pullRequestDetailSummary(data: PullRequestDetail | null) {
404 return data === null ? null : { ...data, checksState: pullRequestChecksState(data.checks) };
405 }
406
@@ -415,7 +411,9 @@ function useDisplayedPullRequestDetail(
411 activity: PullRequestActivity | null,
412 canWriteSourceControl: boolean,
413 ) {
418 - // Calls no hooks, so the compiler needs the directive to memoize it.
414 + // Kept: hooks consume `detail` (the branch refs query keyed on `detail.workspaceRoot`, the stack
415 + // query, the guide writer) and plain calls read it afterwards (`isStackedPullRequestBase`), so a
416 + // body-level derivation gets no cache scope. A hook's return value is frozen and stays cached.
417 "use memo";
418 const listSummary = listEntry === null ? null : pullRequestListEntryToSummary(listEntry);
419 // The list row is also published to the shared cache, but only after this commit's layout
@@ -485,13 +483,11 @@ function useDisplayedPullRequestDetail(
483 return { sharedSummary, coreDetail, detail };
484 }
485
488 -function useMarkdownContext(
486 +function pullRequestMarkdownContext(
487 hostClient: ReturnType<typeof sourceControlClients.get>,
488 repositoryUrl: string | null,
489 threadRef: ScopedThreadRef | null,
490 ) {
493 - // Calls no hooks, so the compiler needs the directive to memoize it.
494 - "use memo";
491 return {
492 repositoryUrl:
493 repositoryUrl === null ? null : hostClient.referenceAutolinkRepositoryUrl(repositoryUrl),
@@ -499,13 +495,11 @@ function useMarkdownContext(
495 };
496 }
497
502 -function useStackReference(
498 +function pullRequestStackReference(
499 detail: Pick<PullRequestDetail, "url" | "capabilities"> | null,
500 reference: PullRequestRef,
501 supportsThreadPullRequests: boolean,
502 ) {
507 - // Calls no hooks, so the compiler needs the directive to memoize it.
508 - "use memo";
503 return detail === null || detail.capabilities.stacks !== true || !supportsThreadPullRequests
504 ? null
505 : { ...reference, host: reference.host ?? parseChangeRequestUrl(detail.url)?.host };
@@ -551,11 +545,17 @@ export function PullRequestDetailPanel({
545 const repositoryIdentity = project?.repositoryIdentity;
546 const supportsThreadPullRequests =
547 environmentConfigs.get(environmentId)?.environment.capabilities.threadPullRequests === true;
554 - const reference = useResolvedPullRequestReference(
548 + const reference = resolvePullRequestReference(
549 requestedReference,
550 repositoryIdentity,
551 supportsThreadPullRequests,
552 );
553 + const loadingCheckoutCommand = loadingPullRequestCheckoutCommand(reference, repositoryIdentity);
554 + const unavailableGitHubUrl = gitHubPullRequestBrowserUrl(
555 + repositoryIdentity,
556 + reference.repository,
557 + reference.number,
558 + );
559 const pullRequestKey = `${reference.projectId}:${reference.host ?? ""}:${reference.repository}#${reference.number}`;
560 const matchingListEntry =
561 listEntry?.projectId === reference.projectId &&
@@ -711,7 +711,7 @@ export function PullRequestDetailPanel({
711 cached: cachedDetail,
712 reference,
713 });
714 - const detailSummary = usePullRequestDetailSummary(detailQuery.data);
714 + const detailSummary = pullRequestDetailSummary(detailQuery.data);
715 const observedSummary = useSharedPullRequestSummary(
716 environmentId,
717 reference,
@@ -761,7 +761,8 @@ export function PullRequestDetailPanel({
761 }
762 const repositoryUrl = detail === null ? null : changeRequestRepositoryUrl(detail.url);
763 const hostClient = sourceControlClients.get(detail?.provider);
764 - const markdownContext = useMarkdownContext(hostClient, repositoryUrl, threadRef);
764 + const openOnHostText = openOnHostLabel(hostClient);
765 + const markdownContext = pullRequestMarkdownContext(hostClient, repositoryUrl, threadRef);
766 const authorProfileUrl =
767 detail?.author && repositoryUrl !== null
768 ? hostClient.authorProfileUrl(detail.author.login, repositoryUrl)
@@ -774,7 +775,7 @@ export function PullRequestDetailPanel({
775 detail?.headRepositoryNameWithOwner,
776 changeRequestRepositoryUrl(handoffSummary.url),
777 )
777 - : loadingPullRequestCheckoutCommand(reference, repositoryIdentity);
778 + : loadingCheckoutCommand;
779 const branchRefsQuery = useEnvironmentQuery(
780 detail === null
781 ? null
@@ -790,7 +791,7 @@ export function PullRequestDetailPanel({
791 const isStackedPullRequest =
792 detail !== null &&
793 isStackedPullRequestBase(detail.baseBranch, branchRefsQuery.data?.refs ?? []);
793 - const stackReference = useStackReference(detail, reference, supportsThreadPullRequests);
794 + const stackReference = pullRequestStackReference(detail, reference, supportsThreadPullRequests);
795 const nativeStackQuery = usePullRequestStack(environmentId, stackReference);
796 const nativeStack = nativeStackQuery.data;
797 const supportsStackActions =
@@ -880,11 +881,6 @@ export function PullRequestDetailPanel({
881 const [titleSaving, setTitleSaving] = useState(false);
882 const newThread = useNewThreadHandler();
883 const { environments } = useEnvironments();
883 - const unavailableGitHubUrl = gitHubPullRequestBrowserUrl(
884 - repositoryIdentity,
885 - reference.repository,
886 - reference.number,
887 - );
884 const pickableEnvironments =
885 context === "page"
886 ? resolvePickableEnvironments(
@@ -1722,7 +1718,7 @@ export function PullRequestDetailPanel({
1718 </button>
1719 }
1720 />
1725 - <TooltipPopup side="top">{openOnHostLabel(hostClient)}</TooltipPopup>
1721 + <TooltipPopup side="top">{openOnHostText}</TooltipPopup>
1722 </Tooltip>
1723 </>
1724 ) : null}
@@ -1781,7 +1777,7 @@ export function PullRequestDetailPanel({
1777 </button>
1778 }
1779 />
1784 - <TooltipPopup side="top">{openOnHostLabel(hostClient)}</TooltipPopup>
1780 + <TooltipPopup side="top">{openOnHostText}</TooltipPopup>
1781 </Tooltip>
1782 <Tooltip>
1783 <TooltipTrigger
@@ -2206,7 +2202,7 @@ export function PullRequestDetailPanel({
2202 ) : null}
2203 <MenuItem onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}>
2204 <ArrowUpRightIcon className="size-3.5" />
2209 - {openOnHostLabel(hostClient)}
2205 + {openOnHostText}
2206 </MenuItem>
2207 <MenuItem onClick={() => copyReference(detail.url, "PR link")}>
2208 <LinkIcon className="size-3.5" />