The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the scratch project hook compiles without manual memoization (#20673)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:54 UTC
165fa98c8aff86881895f23d6efe479a741c39b1
1 file changed
+30
-46
apps/web/src/hooks/useScratchProject.ts
+30
-46
@@ -6,7 +6,6 @@ import {
6
} from "@t3tools/client-runtime/state/runtime";
7
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
8
import type { EnvironmentId } from "@t3tools/contracts";
9
-import { useCallback } from "react";
9
10
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
11
import { useEnvironments } from "~/state/environments";
@@ -29,54 +28,39 @@ export function useScratchProject() {
28
const openScratch = useAtomCommand(projectEnvironment.openScratch, { reportFailure: false });
29
const handleNewThread = useNewThreadHandler();
30
32
- const scratchWorkspaceRootFor = useCallback(
33
- (environmentId: EnvironmentId | null): string | null => {
34
- const environment = environments.find((entry) => entry.environmentId === environmentId);
35
- return availableScratchWorkspaceRoot(
36
- environment?.connection.phase,
37
- environment?.serverConfig,
38
- );
39
- },
40
- [environments],
41
- );
31
+ const scratchWorkspaceRootFor = (environmentId: EnvironmentId | null): string | null => {
32
+ const environment = environments.find((entry) => entry.environmentId === environmentId);
33
+ return availableScratchWorkspaceRoot(environment?.connection.phase, environment?.serverConfig);
34
+ };
35
43
- const scratchEnvironmentId = useCallback(
44
- (current: EnvironmentId | null): EnvironmentId | null => {
45
- if (current !== null) return scratchWorkspaceRootFor(current) !== null ? current : null;
46
- const offering = environments.filter(
47
- (entry) => scratchWorkspaceRootFor(entry.environmentId) !== null,
48
- );
49
- return offering.length === 1 ? (offering[0]?.environmentId ?? null) : null;
50
- },
51
- [environments, scratchWorkspaceRootFor],
52
- );
36
+ const scratchEnvironmentId = (current: EnvironmentId | null): EnvironmentId | null => {
37
+ if (current !== null) return scratchWorkspaceRootFor(current) !== null ? current : null;
38
+ const offering = environments.filter(
39
+ (entry) => scratchWorkspaceRootFor(entry.environmentId) !== null,
40
+ );
41
+ return offering.length === 1 ? (offering[0]?.environmentId ?? null) : null;
42
+ };
43
54
- const openScratchProject = useCallback(
55
- async (
56
- environmentId: EnvironmentId,
57
- failureTitle = "Could not start without a project",
58
- ): Promise<EnvironmentProject | null> => {
59
- const result = await openScratch({ environmentId, input: {} });
60
- if (result._tag === "Success") return result.value;
61
- if (!isAtomCommandInterrupted(result)) {
62
- reportScratchFailure(failureTitle, squashAtomCommandFailure(result));
63
- }
64
- return null;
65
- },
66
- [openScratch],
67
- );
44
+ const openScratchProject = async (
45
+ environmentId: EnvironmentId,
46
+ failureTitle = "Could not start without a project",
47
+ ): Promise<EnvironmentProject | null> => {
48
+ const result = await openScratch({ environmentId, input: {} });
49
+ if (result._tag === "Success") return result.value;
50
+ if (!isAtomCommandInterrupted(result)) {
51
+ reportScratchFailure(failureTitle, squashAtomCommandFailure(result));
52
+ }
53
+ return null;
54
+ };
55
69
- const startScratchThread = useCallback(
70
- async (environmentId: EnvironmentId) => {
71
- const project = await openScratchProject(environmentId);
72
- if (project) {
73
- await handleNewThread(scopeProjectRef(project.environmentId, project.id)).catch(
74
- (error: unknown) => reportScratchFailure("Could not start without a project", error),
75
- );
76
- }
77
- },
78
- [handleNewThread, openScratchProject],
79
- );
56
+ const startScratchThread = async (environmentId: EnvironmentId) => {
57
+ const project = await openScratchProject(environmentId);
58
+ if (project) {
59
+ await handleNewThread(scopeProjectRef(project.environmentId, project.id)).catch(
60
+ (error: unknown) => reportScratchFailure("Could not start without a project", error),
61
+ );
62
+ }
63
+ };
64
65
return { scratchWorkspaceRootFor, scratchEnvironmentId, openScratchProject, startScratchThread };
66
}