TypeScript
perf(web): the index route compiles with the React Compiler (#20580)
Julius Marminge2814dc9c4885
diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsxindex 19058576542..382c3cbb77a 100644--- a/apps/web/src/routes/_chat.index.tsx+++ b/apps/web/src/routes/_chat.index.tsx@@ -2,7 +2,7 @@ import { RefreshIcon } from "~/components/ui/refresh-icon";import { scopeProjectRef } from "@t3tools/client-runtime/environment";import { createFileRoute, Link, useRouter } from "@tanstack/react-router";import { LinkIcon, PlusIcon } from "lucide-react";-import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";+import { useEffect, useEffectEvent, useRef, useState } from "react";import { isLocalEnvironmentDisabled } from "../localEnvironment";import { isElectron } from "../env";@@ -44,39 +44,35 @@ function IndexDraftLanding() {// Read at effect time: this page stays mounted while a navigation away from// "/" is still loading, but the router already points at the new location.const isStillOnIndex = useEffectEvent(() => router.state.location.pathname === "/");- const startingRef = useRef(false);+ // One start per attempt; a retry request opens the next attempt.+ const startedAttemptRef = useRef<number | null>(null);const [startState, setStartState] = useState({ failed: false, retryRequest: 0 });- const mostRecentProject = useMemo(- () =>- bootstrapped- ? (sortScopedProjectsForSidebar(projects, threads, "updated_at")[0] ?? null)- : null,- [bootstrapped, projects, threads],- );+ const mostRecentProject = bootstrapped+ ? (sortScopedProjectsForSidebar(projects, threads, "updated_at")[0] ?? null)+ : null;+ const attempt = startState.retryRequest;useEffect(() => {// Starting a draft after the user has left would replace the page they picked.- if (mostRecentProject === null || startingRef.current || !isStillOnIndex()) {+ if (mostRecentProject === null || startedAttemptRef.current === attempt || !isStillOnIndex()) {return;}const projectRef = scopeProjectRef(mostRecentProject.environmentId, mostRecentProject.id);if (readProject(projectRef) === null) {return;}- startingRef.current = true;+ startedAttemptRef.current = attempt;void handleNewThread(projectRef, { replace: true }).then((opened) => {if (opened === null) {- startingRef.current = false;setStartState((state) => ({ ...state, retryRequest: state.retryRequest + 1 }));}}).catch(() => {- startingRef.current = false;setStartState((state) => ({ ...state, failed: true }));});- }, [handleNewThread, mostRecentProject, startState.retryRequest]);+ }, [attempt, handleNewThread, mostRecentProject]);if (!bootstrapped) {return null;