@devries-cameron20 / t3code Mirror · read-only / commits / d793dddd7a
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, 08:00 UTC

perf(web): the link pull request dialog compiles with the React Compiler (#20495)

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

Julius Marminge committed Oct 16, 2026 at 18:53 UTC d793dddd7ae562e469b4e4390d153bf0ddb0802d
2 files changed +55 -46
apps/web/reactCompiledFiles.ts
+1
@@ -70,4 +70,5 @@ export const REACT_COMPILED_FILES = [
70 "apps/web/src/components/pullRequest/usePullRequestActions.ts",
71 "apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx",
72 "apps/web/src/components/pullRequest/PullRequestThreadLinks.tsx",
73 + "apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx",
74 ] as const;
apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx
+54 -46
@@ -1,7 +1,8 @@
1 import { pullRequestHostOf, type ScopedThreadRef } from "@t3tools/contracts";
2 import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
3 import { useAtomValue } from "@effect/atom-react";
4 -import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4 +import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
5 +import { useEffect, useRef, useState } from "react";
6
7 import { parseChangeRequestUrl } from "~/lib/openPullRequestLink";
8 import { parsePullRequestReference } from "~/pullRequestReference";
@@ -104,6 +105,33 @@ export function resolveLinkPullRequestInput(input: {
105 };
106 }
107
108 +function resolveOwnProject(
109 + environmentProjects: ReturnType<typeof useProjects>,
110 + projectId: LinkPullRequestDialogProps["projectId"],
111 +) {
112 + const project = environmentProjects.find((candidate) => candidate.id === projectId);
113 + const identity = project?.repositoryIdentity;
114 + if (!project || !identity) return null;
115 + const repository =
116 + identity.displayName ??
117 + (identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);
118 + if (repository === null) return null;
119 + const definition = sourceControlClients.get(identity.provider ?? "unknown");
120 + const host = pullRequestHostOf(identity, definition.kind);
121 + return {
122 + host,
123 + repository,
124 + webUrl: (number: number) =>
125 + definition.changeRequestUrl({
126 + host,
127 + repository,
128 + number,
129 + remoteUrl: identity.locator.remoteUrl,
130 + webUrl: identity.webUrl,
131 + }),
132 + };
133 +}
134 +
135 function LinkPullRequestDialog({
136 open,
137 threadRef,
@@ -115,70 +143,50 @@ function LinkPullRequestDialog({
143 const [dirty, setDirty] = useState(false);
144 const [submitError, setSubmitError] = useState<string | null>(null);
145 const projects = useProjects();
118 - const environmentProjects = useMemo(
119 - () => projects.filter((project) => project.environmentId === threadRef.environmentId),
120 - [projects, threadRef.environmentId],
146 + const ownProject = resolveOwnProject(
147 + projects.filter((project) => project.environmentId === threadRef.environmentId),
148 + projectId,
149 );
122 - const ownProject = useMemo(() => {
123 - const project = environmentProjects.find((candidate) => candidate.id === projectId);
124 - const identity = project?.repositoryIdentity;
125 - if (!project || !identity) return null;
126 - const repository =
127 - identity.displayName ??
128 - (identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);
129 - if (repository === null) return null;
130 - const definition = sourceControlClients.get(identity.provider ?? "unknown");
131 - const host = pullRequestHostOf(identity, definition.kind);
132 - return {
133 - host,
134 - repository,
135 - webUrl: (number: number) =>
136 - definition.changeRequestUrl({
137 - host,
138 - repository,
139 - number,
140 - remoteUrl: identity.locator.remoteUrl,
141 - webUrl: identity.webUrl,
142 - }),
143 - };
144 - }, [environmentProjects, projectId]);
150 const linking = usePullRequestLinking(threadRef.environmentId);
151 const [pending, setPending] = useState(false);
152
153 + const [openSeen, setOpenSeen] = useState(open);
154 + if (openSeen !== open) {
155 + setOpenSeen(open);
156 + if (open) {
157 + setReference("");
158 + setDirty(false);
159 + setSubmitError(null);
160 + }
161 + }
162 useEffect(() => {
163 if (!open) return;
150 - setReference("");
151 - setDirty(false);
152 - setSubmitError(null);
164 const frame = window.requestAnimationFrame(() => inputRef.current?.focus());
165 return () => window.cancelAnimationFrame(frame);
166 }, [open]);
167
157 - const resolved = useMemo(
158 - () =>
159 - resolveLinkPullRequestInput({
160 - reference,
161 - project: ownProject,
162 - hasProject: (reference) => linking.canLink(reference.url),
163 - }),
164 - [linking, ownProject, reference],
165 - );
168 + const resolved = resolveLinkPullRequestInput({
169 + reference,
170 + project: ownProject,
171 + hasProject: (reference) => linking.canLink(reference.url),
172 + });
173
167 - const submit = useCallback(async () => {
174 + const submit = async () => {
175 setDirty(true);
176 if (resolved === null || "error" in resolved) return;
177 setSubmitError(null);
178 setPending(true);
172 - try {
173 - await linking.changeLink(threadRef, resolved.link.url, true);
174 - } catch (error) {
179 + const result = await settlePromise(() =>
180 + linking.changeLink(threadRef, resolved.link.url, true),
181 + );
182 + setPending(false);
183 + if (result._tag === "Failure") {
184 + const error = squashAtomCommandFailure(result);
185 setSubmitError(error instanceof Error ? error.message : "Could not link the pull request.");
186 return;
177 - } finally {
178 - setPending(false);
187 }
188 onOpenChange(false);
181 - }, [linking, onOpenChange, resolved, threadRef]);
189 + };
190
191 const validation = !dirty
192 ? null