@devries-cameron20 / t3code Mirror · read-only / commits / 36c1fe50ac
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, 06:45 UTC

perf(web): the new project hook compiles without manual memoization (#20675)

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

Julius Marminge committed Oct 16, 2026 at 21:54 UTC 36c1fe50ac97748f39e1439bffb2b436d338740e
1 file changed +92 -99
apps/web/src/hooks/useNewProject.ts
+92 -99
@@ -8,7 +8,6 @@ import {
8 squashAtomCommandFailure,
9 } from "@t3tools/client-runtime/state/runtime";
10 import type { EnvironmentId } from "@t3tools/contracts";
11 -import { useCallback } from "react";
11
12 import { stackedThreadToast, toastManager } from "~/components/ui/toast";
13 import { waitForProject } from "~/state/entities";
@@ -30,113 +29,107 @@ export function useNewProject() {
29 });
30 const handleNewThread = useNewThreadHandler();
31
33 - const publishNewRepository = useCallback(
34 - async (input: {
35 - readonly environmentId: EnvironmentId;
36 - readonly workspaceRoot: string;
37 - readonly target: NewProjectPublishTarget;
38 - }) => {
39 - const { label } = input.target.definition;
40 - const result = await publishRepository({
41 - environmentId: input.environmentId,
42 - input: {
43 - cwd: input.workspaceRoot,
44 - provider: input.target.definition.kind,
45 - repository: getNewProjectRepository(input.target, input.workspaceRoot),
46 - visibility: "private",
47 - },
48 - });
49 - if (result._tag === "Failure") {
50 - if (!isAtomCommandInterrupted(result)) {
51 - toastManager.add(
52 - stackedThreadToast({
53 - type: "error",
54 - title: `Could not create the ${label} repository`,
55 - description: `${errorMessage(squashAtomCommandFailure(result))} Use Publish Repository in the Git menu to try again.`,
56 - }),
57 - );
58 - }
59 - return;
60 - }
61 - toastManager.add(
62 - stackedThreadToast({
63 - type: "success",
64 - title: `Published to ${label}`,
65 - description: result.value.repository.nameWithOwner,
66 - }),
67 - );
68 - },
69 - [publishRepository],
70 - );
71 -
72 - return useCallback(
73 - async (input: {
74 - readonly environmentId: EnvironmentId;
75 - readonly name: string;
76 - readonly publishTo: NewProjectPublishTarget | null;
77 - }): Promise<boolean> => {
78 - const result = await createNew({
79 - environmentId: input.environmentId,
80 - input: { name: input.name },
81 - });
82 - if (result._tag === "Failure") {
83 - if (!isAtomCommandInterrupted(result)) {
84 - toastManager.add(
85 - stackedThreadToast({
86 - type: "error",
87 - title: "Could not create the project",
88 - description: errorMessage(squashAtomCommandFailure(result)),
89 - }),
90 - );
91 - }
92 - return false;
93 - }
94 -
95 - const { projectId, workspaceRoot, commitError } = result.value;
96 - toastManager.add(
97 - stackedThreadToast(
98 - commitError === undefined
99 - ? { type: "success", title: `Created ${input.name}`, description: workspaceRoot }
100 - : {
101 - type: "warning",
102 - title: `Created ${input.name} without a first commit`,
103 - description: `${commitError} The project is in ${workspaceRoot}.`,
104 - },
105 - ),
106 - );
107 - if (input.publishTo) {
108 - void publishNewRepository({
109 - environmentId: input.environmentId,
110 - workspaceRoot,
111 - target: input.publishTo,
112 - });
113 - }
114 -
115 - const projectRef = scopeProjectRef(input.environmentId, projectId);
116 - // Drafts key off the project's stored path, so wait for the create event
117 - // to reach the store before opening one.
118 - const project = await waitForProject(projectRef).catch((error: unknown) => {
32 + const publishNewRepository = async (input: {
33 + readonly environmentId: EnvironmentId;
34 + readonly workspaceRoot: string;
35 + readonly target: NewProjectPublishTarget;
36 + }) => {
37 + const { label } = input.target.definition;
38 + const result = await publishRepository({
39 + environmentId: input.environmentId,
40 + input: {
41 + cwd: input.workspaceRoot,
42 + provider: input.target.definition.kind,
43 + repository: getNewProjectRepository(input.target, input.workspaceRoot),
44 + visibility: "private",
45 + },
46 + });
47 + if (result._tag === "Failure") {
48 + if (!isAtomCommandInterrupted(result)) {
49 toastManager.add(
50 stackedThreadToast({
51 type: "error",
122 - title: "Failed to open project",
123 - description: `${errorMessage(error)} It will appear in the sidebar once this client catches up.`,
52 + title: `Could not create the ${label} repository`,
53 + description: `${errorMessage(squashAtomCommandFailure(result))} Use Publish Repository in the Git menu to try again.`,
54 }),
55 );
126 - return null;
127 - });
128 - if (project === null) return true;
129 - await handleNewThread(projectRef).catch((error: unknown) => {
56 + }
57 + return;
58 + }
59 + toastManager.add(
60 + stackedThreadToast({
61 + type: "success",
62 + title: `Published to ${label}`,
63 + description: result.value.repository.nameWithOwner,
64 + }),
65 + );
66 + };
67 +
68 + return async (input: {
69 + readonly environmentId: EnvironmentId;
70 + readonly name: string;
71 + readonly publishTo: NewProjectPublishTarget | null;
72 + }): Promise<boolean> => {
73 + const result = await createNew({
74 + environmentId: input.environmentId,
75 + input: { name: input.name },
76 + });
77 + if (result._tag === "Failure") {
78 + if (!isAtomCommandInterrupted(result)) {
79 toastManager.add(
80 stackedThreadToast({
81 type: "error",
133 - title: "Failed to open project",
134 - description: errorMessage(error),
82 + title: "Could not create the project",
83 + description: errorMessage(squashAtomCommandFailure(result)),
84 }),
85 );
86 + }
87 + return false;
88 + }
89 +
90 + const { projectId, workspaceRoot, commitError } = result.value;
91 + toastManager.add(
92 + stackedThreadToast(
93 + commitError === undefined
94 + ? { type: "success", title: `Created ${input.name}`, description: workspaceRoot }
95 + : {
96 + type: "warning",
97 + title: `Created ${input.name} without a first commit`,
98 + description: `${commitError} The project is in ${workspaceRoot}.`,
99 + },
100 + ),
101 + );
102 + if (input.publishTo) {
103 + void publishNewRepository({
104 + environmentId: input.environmentId,
105 + workspaceRoot,
106 + target: input.publishTo,
107 });
138 - return true;
139 - },
140 - [createNew, handleNewThread, publishNewRepository],
141 - );
108 + }
109 +
110 + const projectRef = scopeProjectRef(input.environmentId, projectId);
111 + // Drafts key off the project's stored path, so wait for the create event
112 + // to reach the store before opening one.
113 + const project = await waitForProject(projectRef).catch((error: unknown) => {
114 + toastManager.add(
115 + stackedThreadToast({
116 + type: "error",
117 + title: "Failed to open project",
118 + description: `${errorMessage(error)} It will appear in the sidebar once this client catches up.`,
119 + }),
120 + );
121 + return null;
122 + });
123 + if (project === null) return true;
124 + await handleNewThread(projectRef).catch((error: unknown) => {
125 + toastManager.add(
126 + stackedThreadToast({
127 + type: "error",
128 + title: "Failed to open project",
129 + description: errorMessage(error),
130 + }),
131 + );
132 + });
133 + return true;
134 + };
135 }