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 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-13 08:12:42 +05:30
1 parent a143fa3c56
commit 346247bf1a
1 file changed
+8 -3
+8 -3
View File
@@ -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;