From 346247bf1a461d200209b3f33f2bb7f148987b1f Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Tue, 13 Oct 2026 08:12:42 +0530 Subject: [PATCH] fix(web): leaving the home page while the app loads no longer bounces you to a new draft (#18672) Co-authored-by: PR Batch Tester Co-authored-by: Claude Opus 5.5 --- apps/web/src/routes/_chat.index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsx index 61e9e7a2e3a28d017b6d69e8970237c8a3ded809..b1f4343b385ae39ee6cf6f8ecda363d8269305f2 100644 --- a/apps/web/src/routes/_chat.index.tsx +++ b/apps/web/src/routes/_chat.index.tsx @@ -1,8 +1,8 @@ import { RefreshIcon } from "~/components/ui/refresh-icon"; import { scopeProjectRef } from "@t3tools/client-runtime/environment"; -import { createFileRoute, Link } from "@tanstack/react-router"; +import { createFileRoute, Link, useRouter } from "@tanstack/react-router"; import { LinkIcon, PlusIcon } from "lucide-react"; -import { useEffect, useMemo, useRef, useState } from "react"; +import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react"; import { isLocalEnvironmentDisabled } from "../localEnvironment"; import { isElectron } from "../env"; @@ -44,6 +44,10 @@ function IndexDraftLanding() { const threads = useThreadShells(); const bootstrapped = useAllEnvironmentShellsBootstrapped(); const handleNewThread = useNewThreadHandler(); + const router = useRouter(); + // 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); const [startState, setStartState] = useState({ failed: false, retryRequest: 0 }); @@ -56,7 +60,8 @@ function IndexDraftLanding() { ); useEffect(() => { - if (mostRecentProject === null || startingRef.current) { + // Starting a draft after the user has left would replace the page they picked. + if (mostRecentProject === null || startingRef.current || !isStillOnIndex()) { return; } startingRef.current = true; -- 2.54.0