Skip to content
TypeScript

perf(web): pull request actions compile with the React Compiler (#20492)

Julius Marminge409140911b59
diff --git a/apps/web/reactCompiledFiles.ts b/apps/web/reactCompiledFiles.ts
index a9a8ea0ce17..385e42cc9cc 100644
--- a/apps/web/reactCompiledFiles.ts
+++ b/apps/web/reactCompiledFiles.ts
@@ -67,4 +67,5 @@ export const REACT_COMPILED_FILES = [
"apps/web/src/components/device/DevicePanel.tsx",
"apps/web/src/components/desktop/SshPasswordPromptDialog.tsx",
"apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx",
+ "apps/web/src/components/pullRequest/usePullRequestActions.ts",
] as const;
diff --git a/apps/web/src/components/pullRequest/usePullRequestActions.ts b/apps/web/src/components/pullRequest/usePullRequestActions.ts
index df02c49eb9c..4fa868f5cb1 100644
--- a/apps/web/src/components/pullRequest/usePullRequestActions.ts
+++ b/apps/web/src/components/pullRequest/usePullRequestActions.ts
@@ -9,7 +9,7 @@ import type {
PullRequestMergeMethod,
PullRequestRef,
} from "@t3tools/contracts";
-import { useCallback, useRef, useState } from "react";
+import { useRef, useState } from "react";
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
import { useClientSettings, useEnvironmentSettings } from "~/hooks/useSettings";
import {
@@ -43,7 +43,7 @@ export function usePullRequestDefaultMergeMethodResolver(
const grouping = useClientSettings(selectProjectGroupingSettings);
const projects = useProjects();
const primaryEnvironmentId = usePrimaryEnvironmentId();
- return useCallback(() => {
+ return () => {
if (projectDefault != null) return projectDefault;
if (Object.keys(legacyOverrides).length === 0) return undefined;
const project = projects.find(
@@ -58,15 +58,7 @@ export function usePullRequestDefaultMergeMethodResolver(
}).get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, grouping);
return legacyOverrides[key];
- }, [
- projectDefault,
- projects,
- environmentId,
- projectId,
- grouping,
- primaryEnvironmentId,
- legacyOverrides,
- ]);
+ };
}
const ACTION_SUCCESS_LABELS: Record<PullRequestAction, string> = {
@@ -140,28 +132,29 @@ export function usePullRequestActionRunner({
if (pendingRef.current || reference === null) return;
pendingRef.current = true;
setActionPending(true);
- try {
- const result = await runAction({
- environmentId,
- input: {
- ...reference,
- action,
- ...(method ? { mergeMethod: method } : resolveMergeMethod ? { resolveMergeMethod } : {}),
- },
- });
- if (result._tag === "Failure") throw squashAtomCommandFailure(result);
- toastManager.add({ type: "success", title: ACTION_SUCCESS_LABELS[action] });
- onSuccess?.(action);
- } catch (failure) {
+ const result = await runAction({
+ environmentId,
+ input: {
+ ...reference,
+ action,
+ ...(method ? { mergeMethod: method } : resolveMergeMethod ? { resolveMergeMethod } : {}),
+ },
+ });
+ pendingRef.current = false;
+ setActionPending(false);
+ if (result._tag === "Failure") {
toastManager.add({
type: "error",
title: ACTION_FAILURE_LABELS[action],
- description: readableFailure(failure, ACTION_FAILURE_HINTS[action]),
+ description: readableFailure(
+ squashAtomCommandFailure(result),
+ ACTION_FAILURE_HINTS[action],
+ ),
});
- } finally {
- pendingRef.current = false;
- setActionPending(false);
+ return;
}
+ toastManager.add({ type: "success", title: ACTION_SUCCESS_LABELS[action] });
+ onSuccess?.(action);
};
return { actionPending, perform };
@@ -171,55 +164,50 @@ export function usePullRequestCloseBatch(onClosed: (entry: EnvironmentPullReques
const runAction = useAtomCommand(pullRequestEnvironment.runAction, { reportFailure: false });
const pending = useRef(new Set<string>());
const [closingKeys, setClosingKeys] = useState<ReadonlySet<string>>(() => new Set());
- const close = useCallback(
- async (entries: readonly EnvironmentPullRequestEntry[]) => {
- const batch = entries.filter((entry) => {
- const key = pullRequestEntryKey(entry);
- if (entry.state !== "open" || pending.current.has(key)) return false;
- pending.current.add(key);
+ const close = async (entries: readonly EnvironmentPullRequestEntry[]) => {
+ const batch = entries.filter((entry) => {
+ const key = pullRequestEntryKey(entry);
+ if (entry.state !== "open" || pending.current.has(key)) return false;
+ pending.current.add(key);
+ return true;
+ });
+ if (batch.length === 0) return;
+ setClosingKeys(new Set(pending.current));
+ const failures: string[] = [];
+ const outcomes = await Promise.all(
+ batch.map(async (entry) => {
+ const result = await runAction({
+ environmentId: entry.environmentId,
+ input: {
+ projectId: entry.projectId,
+ host: entry.host,
+ repository: entry.repository,
+ number: entry.number,
+ action: "close",
+ },
+ });
+ pending.current.delete(pullRequestEntryKey(entry));
+ setClosingKeys(new Set(pending.current));
+ if (result._tag === "Failure") {
+ failures.push(
+ `#${entry.number}: ${readableFailure(squashAtomCommandFailure(result), ACTION_FAILURE_HINTS.close)}`,
+ );
+ return;
+ }
+ onClosed(entry);
return true;
- });
- if (batch.length === 0) return;
- setClosingKeys(new Set(pending.current));
- let closed = 0;
- const failures: string[] = [];
- await Promise.all(
- batch.map(async (entry) => {
- try {
- const result = await runAction({
- environmentId: entry.environmentId,
- input: {
- projectId: entry.projectId,
- host: entry.host,
- repository: entry.repository,
- number: entry.number,
- action: "close",
- },
- });
- if (result._tag === "Failure") throw squashAtomCommandFailure(result);
- closed++;
- onClosed(entry);
- } catch (failure) {
- failures.push(
- `#${entry.number}: ${readableFailure(failure, ACTION_FAILURE_HINTS.close)}`,
- );
- } finally {
- pending.current.delete(pullRequestEntryKey(entry));
- setClosingKeys(new Set(pending.current));
- }
- }),
- );
- toastManager.add({
- type: failures.length > 0 ? "error" : "success",
- title:
- failures.length > 0
- ? `Closed ${closed} of ${batch.length} pull requests`
- : `Closed ${closed} pull request${closed === 1 ? "" : "s"}`,
- ...(failures.length > 0 ? { description: failures.slice(0, 3).join("\n") } : {}),
- });
- },
- [onClosed, runAction],
- );
+ }),
+ );
+ const closed = outcomes.filter(Boolean).length;
+ toastManager.add({
+ type: failures.length > 0 ? "error" : "success",
+ title:
+ failures.length > 0
+ ? `Closed ${closed} of ${batch.length} pull requests`
+ : `Closed ${closed} pull request${closed === 1 ? "" : "s"}`,
+ ...(failures.length > 0 ? { description: failures.slice(0, 3).join("\n") } : {}),
+ });
+ };
return { close, closingKeys };
}