| ... | @@ -1,8 +1,8 @@ | ... | @@ -1,8 +1,8 @@ |
| 1 | import { RefreshIcon } from "~/components/ui/refresh-icon"; | 1 | import { RefreshIcon } from "~/components/ui/refresh-icon"; |
| 2 | import { scopeProjectRef } from "@t3tools/client-runtime/environment"; | 2 | import { scopeProjectRef } from "@t3tools/client-runtime/environment"; |
| 3 | import { createFileRoute, Link } from "@tanstack/react-router"; | 3 | import { createFileRoute, Link, useRouter } from "@tanstack/react-router"; |
| 4 | import { LinkIcon, PlusIcon } from "lucide-react"; | 4 | import { LinkIcon, PlusIcon } from "lucide-react"; |
| 5 | import { useEffect, useMemo, useRef, useState } from "react"; | 5 | import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react"; |
| 6 | | 6 | |
| 7 | import { isLocalEnvironmentDisabled } from "../localEnvironment"; | 7 | import { isLocalEnvironmentDisabled } from "../localEnvironment"; |
| 8 | import { isElectron } from "../env"; | 8 | import { isElectron } from "../env"; |
| ... | @@ -44,6 +44,10 @@ function IndexDraftLanding() { | ... | @@ -44,6 +44,10 @@ function IndexDraftLanding() { |
| 44 | const threads = useThreadShells(); | 44 | const threads = useThreadShells(); |
| 45 | const bootstrapped = useAllEnvironmentShellsBootstrapped(); | 45 | const bootstrapped = useAllEnvironmentShellsBootstrapped(); |
| 46 | const handleNewThread = useNewThreadHandler(); | 46 | 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 === "/"); |
| 47 | const startingRef = useRef(false); | 51 | const startingRef = useRef(false); |
| 48 | const [startState, setStartState] = useState({ failed: false, retryRequest: 0 }); | 52 | const [startState, setStartState] = useState({ failed: false, retryRequest: 0 }); |
| 49 | | 53 | |
| ... | @@ -56,7 +60,8 @@ function IndexDraftLanding() { | ... | @@ -56,7 +60,8 @@ function IndexDraftLanding() { |
| 56 | ); | 60 | ); |
| 57 | | 61 | |
| 58 | useEffect(() => { | 62 | 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()) { |
| 60 | return; | 65 | return; |
| 61 | } | 66 | } |
| 62 | startingRef.current = true; | 67 | startingRef.current = true; |