Skip to content

Commit d824d65

Browse files
perf(web): the index route compiles with the React Compiler
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a702563 commit d824d65

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

‎apps/web/src/routes/_chat.index.tsx‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RefreshIcon } from "~/components/ui/refresh-icon";
22
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
33
import { createFileRoute, Link, useRouter } from "@tanstack/react-router";
44
import { LinkIcon, PlusIcon } from "lucide-react";
5-
import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
5+
import { useEffect, useEffectEvent, useRef, useState } from "react";
66

77
import { isLocalEnvironmentDisabled } from "../localEnvironment";
88
import { isElectron } from "../env";
@@ -44,39 +44,35 @@ function IndexDraftLanding() {
4444
// Read at effect time: this page stays mounted while a navigation away from
4545
// "/" is still loading, but the router already points at the new location.
4646
const isStillOnIndex = useEffectEvent(() => router.state.location.pathname === "/");
47-
const startingRef = useRef(false);
47+
// One start per attempt; a retry request opens the next attempt.
48+
const startedAttemptRef = useRef<number | null>(null);
4849
const [startState, setStartState] = useState({ failed: false, retryRequest: 0 });
4950

50-
const mostRecentProject = useMemo(
51-
() =>
52-
bootstrapped
53-
? (sortScopedProjectsForSidebar(projects, threads, "updated_at")[0] ?? null)
54-
: null,
55-
[bootstrapped, projects, threads],
56-
);
51+
const mostRecentProject = bootstrapped
52+
? (sortScopedProjectsForSidebar(projects, threads, "updated_at")[0] ?? null)
53+
: null;
54+
const attempt = startState.retryRequest;
5755

5856
useEffect(() => {
5957
// Starting a draft after the user has left would replace the page they picked.
60-
if (mostRecentProject === null || startingRef.current || !isStillOnIndex()) {
58+
if (mostRecentProject === null || startedAttemptRef.current === attempt || !isStillOnIndex()) {
6159
return;
6260
}
6361
const projectRef = scopeProjectRef(mostRecentProject.environmentId, mostRecentProject.id);
6462
if (readProject(projectRef) === null) {
6563
return;
6664
}
67-
startingRef.current = true;
65+
startedAttemptRef.current = attempt;
6866
void handleNewThread(projectRef, { replace: true })
6967
.then((opened) => {
7068
if (opened === null) {
71-
startingRef.current = false;
7269
setStartState((state) => ({ ...state, retryRequest: state.retryRequest + 1 }));
7370
}
7471
})
7572
.catch(() => {
76-
startingRef.current = false;
7773
setStartState((state) => ({ ...state, failed: true }));
7874
});
79-
}, [handleNewThread, mostRecentProject, startState.retryRequest]);
75+
}, [attempt, handleNewThread, mostRecentProject]);
8076

8177
if (!bootstrapped) {
8278
return null;

0 commit comments

Comments
 (0)