Skip to content

Commit 2a12382

Browse files
perf(web): the project clone toasts compile without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a702563 commit 2a12382

1 file changed

Lines changed: 26 additions & 32 deletions

File tree

‎apps/web/src/components/ProjectCloneToastCoordinator.tsx‎

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
type ProjectCloneSnapshot,
1313
type ProjectId,
1414
} from "@t3tools/contracts";
15-
import { useCallback, useEffect, useRef } from "react";
15+
import { useEffect, useRef } from "react";
1616

1717
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
1818
import { useRemoveClonedProject } from "../hooks/useRemoveClonedProject";
@@ -44,6 +44,23 @@ function renderKey(clone: ProjectCloneSnapshot): string {
4444
return `${clone.phase}:${clone.stage}:${clone.percent ?? ""}:${clone.detail ?? ""}:${clone.error ?? ""}`;
4545
}
4646

47+
async function runCloneAction(
48+
title: string,
49+
action: () => Promise<AtomCommandResult<unknown, unknown>>,
50+
) {
51+
const result = await action();
52+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
53+
const error = squashAtomCommandFailure(result);
54+
toastManager.add(
55+
stackedThreadToast({
56+
type: "error",
57+
title,
58+
description: error instanceof Error ? error.message : "An error occurred.",
59+
}),
60+
);
61+
}
62+
}
63+
4764
function EnvironmentCloneToasts({ environmentId }: { environmentId: EnvironmentId }) {
4865
const clones = useEnvironmentProjectClones(environmentId);
4966
const handleNewThread = useNewThreadHandler();
@@ -54,40 +71,18 @@ function EnvironmentCloneToasts({ environmentId }: { environmentId: EnvironmentI
5471
const retryClone = useAtomCommand(sourceControlEnvironment.retryProjectClone, {
5572
reportFailure: false,
5673
});
57-
const runCloneAction = useCallback(
58-
async (title: string, action: () => Promise<AtomCommandResult<unknown, unknown>>) => {
59-
const result = await action();
60-
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
61-
const error = squashAtomCommandFailure(result);
62-
toastManager.add(
63-
stackedThreadToast({
64-
type: "error",
65-
title,
66-
description: error instanceof Error ? error.message : "An error occurred.",
67-
}),
68-
);
69-
}
70-
},
71-
[],
72-
);
7374
const removeClonedProject = useRemoveClonedProject();
7475
const toasts = useRef(new Map<ProjectId, TrackedToast>());
7576

76-
const isViewingProjectDraft = useCallback(
77-
(projectId: ProjectId) => {
78-
if (!routeDraftId) return false;
79-
const draft = useComposerDraftStore.getState().getDraftSession(routeDraftId as DraftId);
80-
return draft?.environmentId === environmentId && draft.projectId === projectId;
81-
},
82-
[environmentId, routeDraftId],
83-
);
77+
const isViewingProjectDraft = (projectId: ProjectId) => {
78+
if (!routeDraftId) return false;
79+
const draft = useComposerDraftStore.getState().getDraftSession(routeDraftId as DraftId);
80+
return draft?.environmentId === environmentId && draft.projectId === projectId;
81+
};
8482

85-
const openProject = useCallback(
86-
(projectId: ProjectId) => {
87-
void handleNewThread(scopeProjectRef(environmentId, projectId));
88-
},
89-
[environmentId, handleNewThread],
90-
);
83+
const openProject = (projectId: ProjectId) => {
84+
void handleNewThread(scopeProjectRef(environmentId, projectId));
85+
};
9186

9287
useEffect(() => {
9388
const seen = new Set<ProjectId>();
@@ -205,7 +200,6 @@ function EnvironmentCloneToasts({ environmentId }: { environmentId: EnvironmentI
205200
openProject,
206201
removeClonedProject,
207202
retryClone,
208-
runCloneAction,
209203
]);
210204

211205
useEffect(

0 commit comments

Comments
 (0)