Skip to content

An open-source, faster Devin alternative

TypeScript

perf(web): prefetch sandbox detail on intent (hover/focus)

Igor Zalutskibbd2d96d1c53
diff --git a/web/src/hooks/use-prefetch.ts b/web/src/hooks/use-prefetch.ts
new file mode 100644
index 00000000..6c82fc4e
--- /dev/null
+++ b/web/src/hooks/use-prefetch.ts
@@ -0,0 +1,20 @@
+import { useQueryClient } from '@tanstack/react-query'
+import { getSessionDetail } from '@/api/client'
+
+/**
+ * Returns a prefetcher for a sandbox detail page. Call it on row hover/focus to
+ * warm the lazy route chunk and the detail query, so the click feels instant.
+ * Cheap + idempotent — the chunk import dedupes and the query has a staleTime.
+ */
+export function usePrefetchSandbox() {
+ const queryClient = useQueryClient()
+ return (sandboxId: string) => {
+ // Warm the code-split SessionDetail chunk (same module the route lazy-loads).
+ void import('@/pages/SessionDetail')
+ void queryClient.prefetchQuery({
+ queryKey: ['session-detail', sandboxId],
+ queryFn: () => getSessionDetail(sandboxId),
+ staleTime: 10_000,
+ })
+ }
+}
diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx
index 275d9112..f2107ff6 100644
--- a/web/src/pages/Dashboard.tsx
+++ b/web/src/pages/Dashboard.tsx
@@ -8,6 +8,7 @@ import {
getSessions,
type Session,
} from '@/api/client'
+import { usePrefetchSandbox } from '@/hooks/use-prefetch'
import { PageHeader } from '@/components/page-header'
import {
Panel,
@@ -42,6 +43,7 @@ function elapsedMinutes(session: Session): number {
}
export default function Dashboard() {
+ const prefetch = usePrefetchSandbox()
const { data: runningSessions, isLoading: loadingRunning } = useQuery({
queryKey: ['sessions', 'running'],
queryFn: () => getSessions('running'),
@@ -66,6 +68,8 @@ export default function Dashboard() {
cell: (s) => (
<Link
to={`/sandboxes/${s.sandboxId}`}
+ onMouseEnter={() => prefetch(s.sandboxId)}
+ onFocus={() => prefetch(s.sandboxId)}
className="text-foreground font-mono text-[13px] underline-offset-4 hover:underline"
>
{s.sandboxId}
@@ -183,10 +187,13 @@ export default function Dashboard() {
}
function SandboxRow({ session }: { session: Session }) {
+ const prefetch = usePrefetchSandbox()
const elapsed = elapsedMinutes(session)
return (
<Link
to={`/sandboxes/${session.sandboxId}`}
+ onMouseEnter={() => prefetch(session.sandboxId)}
+ onFocus={() => prefetch(session.sandboxId)}
className="hover:bg-row-hover flex items-center justify-between px-5 py-3 transition-colors"
>
<div className="flex items-center gap-2.5">
diff --git a/web/src/pages/Sessions.tsx b/web/src/pages/Sessions.tsx
index 203c40d0..2f4f0a5e 100644
--- a/web/src/pages/Sessions.tsx
+++ b/web/src/pages/Sessions.tsx
@@ -3,6 +3,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { Link } from 'react-router-dom'
import { Boxes } from 'lucide-react'
import { notifyError } from '@/lib/errors'
+import { usePrefetchSandbox } from '@/hooks/use-prefetch'
import { deleteSession, getSessions, type Session } from '@/api/client'
import { PageHeader } from '@/components/page-header'
import { Panel } from '@/components/panel'
@@ -28,6 +29,7 @@ function canDeleteSession(session: Session) {
export default function Sessions() {
const queryClient = useQueryClient()
+ const prefetch = usePrefetchSandbox()
const [status, setStatus] = useState<string>('')
const [toDelete, setToDelete] = useState<Session | null>(null)
@@ -75,6 +77,8 @@ export default function Sessions() {
cell: (s) => (
<Link
to={`/sandboxes/${s.sandboxId}`}
+ onMouseEnter={() => prefetch(s.sandboxId)}
+ onFocus={() => prefetch(s.sandboxId)}
className="text-foreground font-mono text-[13px] underline-offset-4 hover:underline"
>
{s.sandboxId}