@devries-cameron20 / t3code-1 / commits / de9756a4fc
Fork 0

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

perf(web): the open panel pull request URL hook compiles without manual memoization (#20679)

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

Julius Marminge committed Oct 16, 2026 at 21:54 UTC de9756a4fc3388e5257c5f188bd3f0cdcedd9e60
1 file changed +42 -29
apps/web/src/hooks/useOpenPanelPullRequestUrl.ts
+42 -29
@@ -1,6 +1,5 @@
1 import { scopeProjectRef } from "@t3tools/client-runtime/environment";
2 import { EnvironmentId, ProjectId, type ScopedThreadRef } from "@t3tools/contracts";
3 -import { useMemo } from "react";
3
4 import {
5 readPullRequestDetailSnapshot,
@@ -14,6 +13,35 @@ import { pullRequestEnvironment } from "../state/pullRequests";
13 import { useEnvironmentQuery } from "../state/query";
14 import { useSupportsMultiplePullRequests } from "./useSupportsMultiplePullRequests";
15
16 +type PanelPullRequestSurface = Extract<
17 + NonNullable<ReturnType<typeof selectActiveRightPanelSurface>>,
18 + { kind: "pull-request" }
19 +>;
20 +
21 +// The reference keys the detail query atom, so it must keep its identity across renders.
22 +function usePanelPullRequestReference(
23 + requestedReference: PanelPullRequestSurface | null,
24 + supportsMultiplePullRequests: boolean,
25 + repositoryIdentity: Parameters<typeof resolvePullRequestReferenceHost>[1],
26 +) {
27 + "use memo";
28 + if (requestedReference === null) return null;
29 + const input = {
30 + projectId: ProjectId.make(requestedReference.projectId),
31 + repository: requestedReference.repository,
32 + number: requestedReference.number,
33 + };
34 + return supportsMultiplePullRequests
35 + ? resolvePullRequestReferenceHost(
36 + {
37 + ...input,
38 + ...(requestedReference.host === undefined ? {} : { host: requestedReference.host }),
39 + },
40 + repositoryIdentity,
41 + )
42 + : input;
43 +}
44 +
45 export function useOpenPanelPullRequestUrl(threadRef: ScopedThreadRef | null) {
46 const surface = useRightPanelStore((state) =>
47 selectActiveRightPanelSurface(state.byThreadKey, threadRef),
@@ -28,23 +56,11 @@ export function useOpenPanelPullRequestUrl(threadRef: ScopedThreadRef | null) {
56 ? scopeProjectRef(environmentId, ProjectId.make(requestedReference.projectId))
57 : null,
58 );
31 - const reference = useMemo(() => {
32 - if (requestedReference === null) return null;
33 - const input = {
34 - projectId: ProjectId.make(requestedReference.projectId),
35 - repository: requestedReference.repository,
36 - number: requestedReference.number,
37 - };
38 - return supportsMultiplePullRequests
39 - ? resolvePullRequestReferenceHost(
40 - {
41 - ...input,
42 - ...(requestedReference.host === undefined ? {} : { host: requestedReference.host }),
43 - },
44 - project?.repositoryIdentity,
45 - )
46 - : input;
47 - }, [requestedReference, supportsMultiplePullRequests, project?.repositoryIdentity]);
59 + const reference = usePanelPullRequestReference(
60 + requestedReference,
61 + supportsMultiplePullRequests,
62 + project?.repositoryIdentity,
63 + );
64 const detail = useEnvironmentQuery(
65 reference && environmentId
66 ? pullRequestEnvironment.detail({
@@ -53,17 +69,14 @@ export function useOpenPanelPullRequestUrl(threadRef: ScopedThreadRef | null) {
69 })
70 : null,
71 ).data;
56 - const cachedDetail = useMemo(
57 - () =>
58 - reference && environmentId
59 - ? readPullRequestDetailSnapshot(
60 - typeof window === "undefined" ? undefined : window.localStorage,
61 - environmentId,
62 - reference,
63 - )
64 - : null,
65 - [environmentId, reference],
66 - );
72 + const cachedDetail =
73 + reference && environmentId
74 + ? readPullRequestDetailSnapshot(
75 + typeof window === "undefined" ? undefined : window.localStorage,
76 + environmentId,
77 + reference,
78 + )
79 + : null;
80 return reference
81 ? (resolveDisplayedPullRequestDetail({ live: detail, cached: cachedDetail, reference })?.url ??
82 requestedReference?.url ??