TypeScript
perf(web): the scratch project hook compiles without manual memoization (#20673)
Julius Marminge165fa98c8aff
diff --git a/apps/web/src/hooks/useScratchProject.ts b/apps/web/src/hooks/useScratchProject.tsindex 5ba47ab8529..8b9991f9efc 100644--- a/apps/web/src/hooks/useScratchProject.ts+++ b/apps/web/src/hooks/useScratchProject.ts@@ -6,7 +6,6 @@ import {} from "@t3tools/client-runtime/state/runtime";import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";import type { EnvironmentId } from "@t3tools/contracts";-import { useCallback } from "react";import { stackedThreadToast, toastManager } from "~/components/ui/toast";import { useEnvironments } from "~/state/environments";@@ -29,54 +28,39 @@ export function useScratchProject() {const openScratch = useAtomCommand(projectEnvironment.openScratch, { reportFailure: false });const handleNewThread = useNewThreadHandler();- const scratchWorkspaceRootFor = useCallback(- (environmentId: EnvironmentId | null): string | null => {- const environment = environments.find((entry) => entry.environmentId === environmentId);- return availableScratchWorkspaceRoot(- environment?.connection.phase,- environment?.serverConfig,- );- },- [environments],- );+ const scratchWorkspaceRootFor = (environmentId: EnvironmentId | null): string | null => {+ const environment = environments.find((entry) => entry.environmentId === environmentId);+ return availableScratchWorkspaceRoot(environment?.connection.phase, environment?.serverConfig);+ };- const scratchEnvironmentId = useCallback(- (current: EnvironmentId | null): EnvironmentId | null => {- if (current !== null) return scratchWorkspaceRootFor(current) !== null ? current : null;- const offering = environments.filter(- (entry) => scratchWorkspaceRootFor(entry.environmentId) !== null,- );- return offering.length === 1 ? (offering[0]?.environmentId ?? null) : null;- },- [environments, scratchWorkspaceRootFor],- );+ const scratchEnvironmentId = (current: EnvironmentId | null): EnvironmentId | null => {+ if (current !== null) return scratchWorkspaceRootFor(current) !== null ? current : null;+ const offering = environments.filter(+ (entry) => scratchWorkspaceRootFor(entry.environmentId) !== null,+ );+ return offering.length === 1 ? (offering[0]?.environmentId ?? null) : null;+ };- const openScratchProject = useCallback(- async (- environmentId: EnvironmentId,- failureTitle = "Could not start without a project",- ): Promise<EnvironmentProject | null> => {- const result = await openScratch({ environmentId, input: {} });- if (result._tag === "Success") return result.value;- if (!isAtomCommandInterrupted(result)) {- reportScratchFailure(failureTitle, squashAtomCommandFailure(result));- }- return null;- },- [openScratch],- );+ const openScratchProject = async (+ environmentId: EnvironmentId,+ failureTitle = "Could not start without a project",+ ): Promise<EnvironmentProject | null> => {+ const result = await openScratch({ environmentId, input: {} });+ if (result._tag === "Success") return result.value;+ if (!isAtomCommandInterrupted(result)) {+ reportScratchFailure(failureTitle, squashAtomCommandFailure(result));+ }+ return null;+ };- const startScratchThread = useCallback(- async (environmentId: EnvironmentId) => {- const project = await openScratchProject(environmentId);- if (project) {- await handleNewThread(scopeProjectRef(project.environmentId, project.id)).catch(- (error: unknown) => reportScratchFailure("Could not start without a project", error),- );- }- },- [handleNewThread, openScratchProject],- );+ const startScratchThread = async (environmentId: EnvironmentId) => {+ const project = await openScratchProject(environmentId);+ if (project) {+ await handleNewThread(scopeProjectRef(project.environmentId, project.id)).catch(+ (error: unknown) => reportScratchFailure("Could not start without a project", error),+ );+ }+ };return { scratchWorkspaceRootFor, scratchEnvironmentId, openScratchProject, startScratchThread };}