Skip to content

Commit a8aaa32

Browse files
perf(web): the pull request linking hook compiles without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 70d60e0 commit a8aaa32

2 files changed

Lines changed: 52 additions & 56 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ export const REACT_COMPILED_FILES = [
9696
"apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx",
9797
"apps/web/src/components/ThreadTerminalDrawer.tsx",
9898
"apps/web/src/components/settings/SettingsPanels.tsx",
99+
"apps/web/src/hooks/usePullRequestLinking.ts",
99100
] as const;
Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useMemo } from "react";
21
import { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";
32
import type {
43
EnvironmentId,
@@ -48,61 +47,57 @@ export function usePullRequestLinking(environmentId: EnvironmentId | null | unde
4847
const link = useAtomCommand(threadEnvironment.linkPullRequest, { reportFailure: false });
4948
const unlink = useAtomCommand(threadEnvironment.unlinkPullRequest, { reportFailure: false });
5049
const updateMetadata = useAtomCommand(threadEnvironment.updateMetadata, { reportFailure: false });
51-
return useMemo(() => {
52-
const environmentProjects = projects.filter(
53-
(project) => project.environmentId === environmentId,
54-
);
55-
const canLink = (url: string) => {
56-
const parsed = parseChangeRequestUrl(url);
57-
return parsed !== null && canLinkChangeRequest(mode, environmentProjects, parsed);
58-
};
59-
const isLinked = (
60-
thread: {
61-
readonly pullRequests?: readonly ThreadPullRequestLink[];
62-
readonly linkedPullRequest?: ThreadLinkedPullRequest | null | undefined;
63-
} | null,
64-
url: string,
65-
) => {
66-
if (thread === null || mode === "unsupported") return false;
67-
if (mode !== "multiple")
68-
return (
69-
thread.linkedPullRequest != null &&
70-
matchesLinkedPullRequestUrl(thread.linkedPullRequest, url)
71-
);
72-
const parsed = parseChangeRequestUrl(url);
50+
const environmentProjects = projects.filter((project) => project.environmentId === environmentId);
51+
const canLink = (url: string) => {
52+
const parsed = parseChangeRequestUrl(url);
53+
return parsed !== null && canLinkChangeRequest(mode, environmentProjects, parsed);
54+
};
55+
const isLinked = (
56+
thread: {
57+
readonly pullRequests?: readonly ThreadPullRequestLink[];
58+
readonly linkedPullRequest?: ThreadLinkedPullRequest | null | undefined;
59+
} | null,
60+
url: string,
61+
) => {
62+
if (thread === null || mode === "unsupported") return false;
63+
if (mode !== "multiple")
7364
return (
74-
parsed !== null &&
75-
visibleThreadPullRequests(thread.pullRequests ?? []).some((entry) =>
76-
threadPullRequestKeysEqual(entry, parsed),
77-
)
65+
thread.linkedPullRequest != null &&
66+
matchesLinkedPullRequestUrl(thread.linkedPullRequest, url)
7867
);
79-
};
80-
const changeLink = async (threadRef: ScopedThreadRef, url: string, linked: boolean) => {
81-
const parsed = parseChangeRequestUrl(url);
82-
if (parsed === null || threadRef.environmentId !== environmentId || (linked && !canLink(url)))
83-
throw new Error("The pull request is not available in this environment.");
84-
const legacyProject = findProjectForChangeRequest(environmentProjects, parsed);
85-
const mutation = planThreadPullRequestMutation({
86-
capabilities,
87-
threadId: threadRef.threadId,
88-
reference: { ...parsed, url },
89-
legacyProjectId: legacyProject?.id ?? null,
90-
legacyRepository:
91-
sourceControlRepositorySelector(legacyProject?.repositoryIdentity) ?? undefined,
92-
linked,
93-
});
94-
if (mutation === null)
95-
throw new Error("This environment does not support linking this pull request.");
96-
const result = await (mutation.type === "thread.meta.update"
97-
? updateMetadata({ environmentId: threadRef.environmentId, input: mutation.input })
98-
: mutation.type === "thread.pull-request.link"
99-
? link({ environmentId: threadRef.environmentId, input: mutation.input })
100-
: unlink({ environmentId: threadRef.environmentId, input: mutation.input }));
101-
if (result._tag === "Failure") {
102-
if (isAtomCommandInterrupted(result)) throw new Error("Link update interrupted.");
103-
throw squashAtomCommandFailure(result);
104-
}
105-
};
106-
return { mode, canLink, isLinked, changeLink };
107-
}, [capabilities, environmentId, link, mode, projects, unlink, updateMetadata]);
68+
const parsed = parseChangeRequestUrl(url);
69+
return (
70+
parsed !== null &&
71+
visibleThreadPullRequests(thread.pullRequests ?? []).some((entry) =>
72+
threadPullRequestKeysEqual(entry, parsed),
73+
)
74+
);
75+
};
76+
const changeLink = async (threadRef: ScopedThreadRef, url: string, linked: boolean) => {
77+
const parsed = parseChangeRequestUrl(url);
78+
if (parsed === null || threadRef.environmentId !== environmentId || (linked && !canLink(url)))
79+
throw new Error("The pull request is not available in this environment.");
80+
const legacyProject = findProjectForChangeRequest(environmentProjects, parsed);
81+
const mutation = planThreadPullRequestMutation({
82+
capabilities,
83+
threadId: threadRef.threadId,
84+
reference: { ...parsed, url },
85+
legacyProjectId: legacyProject?.id ?? null,
86+
legacyRepository:
87+
sourceControlRepositorySelector(legacyProject?.repositoryIdentity) ?? undefined,
88+
linked,
89+
});
90+
if (mutation === null)
91+
throw new Error("This environment does not support linking this pull request.");
92+
const result = await (mutation.type === "thread.meta.update"
93+
? updateMetadata({ environmentId: threadRef.environmentId, input: mutation.input })
94+
: mutation.type === "thread.pull-request.link"
95+
? link({ environmentId: threadRef.environmentId, input: mutation.input })
96+
: unlink({ environmentId: threadRef.environmentId, input: mutation.input }));
97+
if (result._tag === "Failure") {
98+
if (isAtomCommandInterrupted(result)) throw new Error("Link update interrupted.");
99+
throw squashAtomCommandFailure(result);
100+
}
101+
};
102+
return { mode, canLink, isLinked, changeLink };
108103
}

0 commit comments

Comments
 (0)