Skip to content

Commit 6c639c3

Browse files
PR Batch Testerclaude
andcommitted
fix(web): leaving the home page while the app loads no longer bounces you to a new draft
The home page opens a draft for the latest project once threads load. It stays mounted while a navigation away from "/" is still loading, but the router already points at the new page, so the draft step's own "did the route change?" guard saw no change and replaced the page the user picked. Tapping "Get the beta app" in the Nightly popup during startup hit this: Settings opened, then the app jumped to a new draft. Only start the draft while the router is still on "/". Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5753207 commit 6c639c3

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

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

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

77
import { isLocalEnvironmentDisabled } from "../localEnvironment";
88
import { isElectron } from "../env";
@@ -44,6 +44,10 @@ function IndexDraftLanding() {
4444
const threads = useThreadShells();
4545
const bootstrapped = useAllEnvironmentShellsBootstrapped();
4646
const handleNewThread = useNewThreadHandler();
47+
const router = useRouter();
48+
// Read at effect time: this page stays mounted while a navigation away from
49+
// "/" is still loading, but the router already points at the new location.
50+
const isStillOnIndex = useEffectEvent(() => router.state.location.pathname === "/");
4751
const startingRef = useRef(false);
4852
const [startState, setStartState] = useState({ failed: false, retryRequest: 0 });
4953

@@ -56,7 +60,8 @@ function IndexDraftLanding() {
5660
);
5761

5862
useEffect(() => {
59-
if (mostRecentProject === null || startingRef.current) {
63+
// Starting a draft after the user has left would replace the page they picked.
64+
if (mostRecentProject === null || startingRef.current || !isStillOnIndex()) {
6065
return;
6166
}
6267
startingRef.current = true;

0 commit comments

Comments
 (0)