Skip to content

Open source alternative to Semrush and Ahrefs

Make AI visibility views load faster (EVE-395) (#862)

Carter Smith4579c3c7a3bf
diff --git a/src/client/features/ai-visibility/AiResearchSetupGate.tsx b/src/client/features/ai-visibility/AiResearchSetupGate.tsx
index 157c3183..3e776b46 100644
--- a/src/client/features/ai-visibility/AiResearchSetupGate.tsx
+++ b/src/client/features/ai-visibility/AiResearchSetupGate.tsx
@@ -8,14 +8,15 @@ import { Card, CardContent } from "@/client/components/ui/card";
import { projectsQueryOptions } from "@/client/features/projects/projectQueries";
import { WebsiteResearchProgress } from "@/client/features/projects/WebsiteResearchProgress";
import { WebsiteSetupReview } from "@/client/features/projects/WebsiteSetupReview";
-import {
- getAiResearchSetup,
- startAiResearchSetup,
-} from "@/serverFunctions/ai-visibility";
+import { startAiResearchSetup } from "@/serverFunctions/ai-visibility";
import { saveProjectWebsiteSetup } from "@/serverFunctions/projectWebsite";
import type { SaveProjectWebsiteSetup } from "@/types/schemas/projectWebsite";
import { SkeletonPageContent } from "@/client/components/SkeletonPresets";
-import { AiQueryError, aiVisibilityKey } from "./shared";
+import {
+ AiQueryError,
+ aiResearchSetupQueryOptions,
+ aiVisibilityKey,
+} from "./shared";
/**
* AI visibility needs research keywords. A project with a website but no
@@ -34,13 +35,8 @@ export function AiResearchSetupGate({
}) {
const queryClient = useQueryClient();
const navigate = useNavigate();
- const setupKey = [...aiVisibilityKey(projectId), "researchSetup"];
- const setup = useQuery({
- queryKey: setupKey,
- queryFn: () => getAiResearchSetup({ data: { projectId } }),
- refetchInterval: (query) =>
- query.state.data?.status === "running" ? 3000 : false,
- });
+ const setupOptions = aiResearchSetupQueryOptions(projectId);
+ const setup = useQuery(setupOptions);
const refresh = () =>
Promise.all([
queryClient.invalidateQueries({ queryKey: aiVisibilityKey(projectId) }),
@@ -53,7 +49,7 @@ export function AiResearchSetupGate({
]);
const start = useMutation({
mutationFn: () => startAiResearchSetup({ data: { projectId } }),
- onSuccess: (data) => queryClient.setQueryData(setupKey, data),
+ onSuccess: (data) => queryClient.setQueryData(setupOptions.queryKey, data),
});
const save = useMutation({
mutationFn: (accepted: Omit<SaveProjectWebsiteSetup, "projectId">) =>
diff --git a/src/client/features/ai-visibility/PromptHistoryPage.tsx b/src/client/features/ai-visibility/PromptHistoryPage.tsx
index e3bb32d8..45879f09 100644
--- a/src/client/features/ai-visibility/PromptHistoryPage.tsx
+++ b/src/client/features/ai-visibility/PromptHistoryPage.tsx
@@ -1,17 +1,17 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { Play } from "lucide-react";
import { BackLink, PageHeader } from "@/client/components/PageHeader";
+import { SkeletonCard } from "@/client/components/SkeletonPresets";
import { Button } from "@/client/components/ui/button";
import { type AiRun } from "@/shared/ai-visibility";
import { PromptAnalysis } from "./PromptAnalysis";
-import { TrackingCostReview } from "./TrackingCostReview";
+import { prefetchRunNowCost, TrackingCostReview } from "./TrackingCostReview";
import {
- AiLoading,
AiQueryError,
AiRunStatus,
+ aiPromptHistoryQueryOptions,
aiVisibilityKey,
- fetchAllAiVisibilityResults,
useAiRunProgress,
useAiVisibilityTracker,
} from "./shared";
@@ -28,17 +28,7 @@ export function PromptHistoryPage({
const [checking, setChecking] = useState(false);
const [startedRun, setStartedRun] = useState<AiRun | null>(null);
const progress = useAiRunProgress(projectId, startedRun);
- const history = useQuery({
- queryKey: [...aiVisibilityKey(projectId), "results", "history", promptId],
- // Read all pages of the latest 50 runs so engine ordering cannot hide
- // a newer execution from the selector.
- queryFn: () =>
- fetchAllAiVisibilityResults({
- projectId,
- promptId,
- includeHistory: true,
- }),
- });
+ const history = useQuery(aiPromptHistoryQueryOptions(projectId, promptId));
const state = trackerQuery.data;
const prompt = state?.prompts.find((item) => item.id === promptId);
const latestRun = history.data?.historyRuns.find((run) =>
@@ -49,6 +39,12 @@ export function PromptHistoryPage({
)?.prompt;
const busy =
progress.run?.status === "queued" || progress.run?.status === "running";
+ const tracker = state?.tracker;
+ // Price this prompt's Run now on load, so the dialog opens on a price.
+ useEffect(() => {
+ if (tracker)
+ prefetchRunNowCost(queryClient, projectId, tracker, [promptId]);
+ }, [queryClient, projectId, promptId, tracker]);
return (
<div className="space-y-5 pt-1">
<BackLink to="/p/$projectId/ai-visibility" params={{ projectId }}>
@@ -89,7 +85,7 @@ export function PromptHistoryPage({
{progress.run && <AiRunStatus run={progress.run} />}
{progress.error && <AiQueryError error={progress.error} />}
{history.isPending ? (
- <AiLoading />
+ <SkeletonCard />
) : history.isError ? (
<AiQueryError
error={history.error}
diff --git a/src/client/features/ai-visibility/PromptInventory.tsx b/src/client/features/ai-visibility/PromptInventory.tsx
index 25bf619b..255eff04 100644
--- a/src/client/features/ai-visibility/PromptInventory.tsx
+++ b/src/client/features/ai-visibility/PromptInventory.tsx
@@ -16,6 +16,7 @@ import {
type AiPrompt,
} from "@/shared/ai-visibility";
import { Button } from "@/client/components/ui/button";
+import { Skeleton } from "@/client/components/ui/skeleton";
import {
Table,
TableBody,
@@ -35,6 +36,7 @@ export function PromptInventory({
search,
engines,
rows,
+ loading,
pending,
onEdit,
onReduce,
@@ -47,6 +49,8 @@ export function PromptInventory({
search: string;
engines: AiEngine[];
rows: AiObservationRow[] | undefined;
+ /** The run's answers are still loading; prompts show before their rates. */
+ loading: boolean;
pending: boolean;
onEdit: (prompt: AiPrompt) => void;
onReduce: (patch: AiTrackerPatch) => void;
@@ -113,10 +117,14 @@ export function PromptInventory({
</Button>
</TableCell>
<TableCell>
- <PromptRate rows={topicRows} kind="mentioned" />
+ <PromptRate
+ rows={topicRows}
+ kind="mentioned"
+ loading={loading}
+ />
</TableCell>
<TableCell>
- <PromptRate rows={topicRows} kind="cited" />
+ <PromptRate rows={topicRows} kind="cited" loading={loading} />
</TableCell>
<TableCell>
<div className="flex items-center justify-end gap-1">
@@ -199,10 +207,18 @@ export function PromptInventory({
</div>
</TableCell>
<TableCell>
- <PromptRate rows={promptRows} kind="mentioned" />
+ <PromptRate
+ rows={promptRows}
+ kind="mentioned"
+ loading={loading}
+ />
</TableCell>
<TableCell>
- <PromptRate rows={promptRows} kind="cited" />
+ <PromptRate
+ rows={promptRows}
+ kind="cited"
+ loading={loading}
+ />
</TableCell>
<TableCell>
<div className="flex items-center justify-end gap-1">
@@ -274,10 +290,13 @@ export function PromptInventory({
function PromptRate({
rows,
kind,
+ loading,
}: {
rows: AiObservationRow[] | undefined;
kind: "mentioned" | "cited";
+ loading: boolean;
}) {
+ if (loading) return <Skeleton className="h-4 w-10" />;
const eligible =
rows?.filter(
(row) =>
diff --git a/src/client/features/ai-visibility/PromptList.tsx b/src/client/features/ai-visibility/PromptList.tsx
index 86fa54b3..459ab8dd 100644
--- a/src/client/features/ai-visibility/PromptList.tsx
+++ b/src/client/features/ai-visibility/PromptList.tsx
@@ -12,11 +12,7 @@ import { getStandardErrorMessage } from "@/client/lib/error-messages";
import type { AiPrompt, AiRun, AiTrackerState } from "@/shared/ai-visibility";
import type { AiTrackerPatch } from "@/types/schemas/ai-visibility";
import { PromptInventory } from "./PromptInventory";
-import {
- AiQueryError,
- aiVisibilityKey,
- fetchAllAiVisibilityResults,
-} from "./shared";
+import { AiQueryError, aiRunResultsQueryOptions } from "./shared";
export function PromptList({
projectId,
@@ -38,18 +34,7 @@ export function PromptList({
reducePending: boolean;
}) {
const [search, setSearch] = useState("");
- // Every answer in the run, so each prompt can show its per-engine result.
- const results = useQuery({
- queryKey: [...aiVisibilityKey(projectId), "results", "all", currentRun?.id],
- queryFn: async () => {
- const result = await fetchAllAiVisibilityResults({
- projectId,
- runId: currentRun?.id,
- });
- return result.rows;
- },
- enabled: Boolean(currentRun),
- });
+ const results = useQuery(aiRunResultsQueryOptions(projectId, currentRun?.id));
const exportMutation = useMutation({
mutationFn: (format: "json" | "csv") =>
exportAiVisibilityData({
@@ -112,11 +97,6 @@ export function PromptList({
}}
/>
)}
- {currentRun && results.isPending && (
- <p className="px-4 py-2 text-xs text-muted-foreground" role="status">
- Loading latest results…
- </p>
- )}
<PromptInventory
projectId={projectId}
prompts={prompts}
@@ -124,6 +104,7 @@ export function PromptList({
search={search}
engines={state.engines}
rows={results.data}
+ loading={results.isLoading}
pending={reducePending}
onEdit={onEdit}
onReduce={onReduce}
diff --git a/src/client/features/ai-visibility/PromptTrackingPage.tsx b/src/client/features/ai-visibility/PromptTrackingPage.tsx
index 3585ff6b..586de08d 100644
--- a/src/client/features/ai-visibility/PromptTrackingPage.tsx
+++ b/src/client/features/ai-visibility/PromptTrackingPage.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { MessageSquare, Play, Plus, Settings2 } from "lucide-react";
import { toast } from "sonner";
@@ -27,7 +27,7 @@ import {
type PromptTrackingTab,
} from "./PromptTrackingTabs";
import { TrackerEditor, TrackerEditorMode } from "./TrackerEditor";
-import { TrackingCostReview } from "./TrackingCostReview";
+import { prefetchRunNowCost, TrackingCostReview } from "./TrackingCostReview";
import { VisibilityTrend } from "./VisibilityTrend";
import { RunStatusLine } from "./RunStatusLine";
import { TrackingScheduleSummary } from "./TrackingScheduleSummary";
@@ -145,6 +145,12 @@ function PromptTrackingContent({
});
const busy =
progress.run?.status === "running" || progress.run?.status === "queued";
+ // Price Run now on load and again when the active prompts or engines
+ // change, so the dialog opens on the current price.
+ const engines = state.engines.join();
+ useEffect(() => {
+ if (tracker) prefetchRunNowCost(queryClient, projectId, tracker);
+ }, [queryClient, projectId, tracker, activePrompts.length, engines]);
const schedule = tracker && (
<TrackingScheduleSummary
tracker={tracker}
diff --git a/src/client/features/ai-visibility/TrackingCostReview.tsx b/src/client/features/ai-visibility/TrackingCostReview.tsx
index 438a75b5..cde9ec6c 100644
--- a/src/client/features/ai-visibility/TrackingCostReview.tsx
+++ b/src/client/features/ai-visibility/TrackingCostReview.tsx
@@ -1,5 +1,11 @@
import { useState } from "react";
-import { keepPreviousData, useMutation, useQuery } from "@tanstack/react-query";
+import {
+ keepPreviousData,
+ queryOptions,
+ useMutation,
+ useQuery,
+ type QueryClient,
+} from "@tanstack/react-query";
import { Loader2 } from "lucide-react";
import { FormDialog } from "@/client/components/FormDialog";
import { Button } from "@/client/components/ui/button";
@@ -26,6 +32,57 @@ import {
} from "@/client/features/rank-tracking/scheduleTime";
import { AiLoading, AiQueryError, aiMoney, aiVisibilityKey } from "./shared";
+const costEstimateQueryOptions = ({
+ projectId,
+ mode,
+ scheduleInterval,
+ promptIds,
+}: {
+ projectId: string;
+ mode: "check" | "schedule";
+ scheduleInterval: AiScheduleInterval;
+ promptIds?: string[];
+}) =>
+ queryOptions({
+ queryKey: [
+ ...aiVisibilityKey(projectId),
+ "estimate",
+ mode,
+ scheduleInterval,
+ promptIds,
+ ],
+ queryFn: () =>
+ estimateAiVisibilityCost({
+ data: {
+ projectId,
+ promptIds,
+ scheduleInterval: mode === "schedule" ? scheduleInterval : undefined,
+ },
+ }),
+ // Price the tracker as it is now each time the dialog opens, showing the
+ // price the page preloaded while that runs.
+ staleTime: 0,
+ retry: false,
+ refetchOnWindowFocus: false,
+ });
+
+/** Starts pricing a run before Run now is clicked, so the dialog opens on a price. */
+export function prefetchRunNowCost(
+ queryClient: QueryClient,
+ projectId: string,
+ tracker: AiTracker,
+ promptIds?: string[],
+) {
+ void queryClient.prefetchQuery(
+ costEstimateQueryOptions({
+ projectId,
+ mode: "check",
+ scheduleInterval: tracker.scheduleInterval,
+ promptIds,
+ }),
+ );
+}
+
export function TrackingCostReview({
projectId,
tracker,
@@ -54,27 +111,13 @@ export function TrackingCostReview({
);
const [scheduleTimeEdited, setScheduleTimeEdited] = useState(false);
const estimate = useQuery({
- queryKey: [
- ...aiVisibilityKey(projectId),
- "estimate",
+ ...costEstimateQueryOptions({
+ projectId,
mode,
scheduleInterval,
promptIds,
- ],
- queryFn: () =>
- estimateAiVisibilityCost({
- data: {
- projectId,
- promptIds,
- scheduleInterval: mode === "schedule" ? scheduleInterval : undefined,
- },
- }),
+ }),
placeholderData: keepPreviousData,
- // Price the tracker as it is now each time the dialog opens.
- staleTime: 0,
- gcTime: 0,
- retry: false,
- refetchOnWindowFocus: false,
});
const cost = estimate.data;
const start = useMutation({
@@ -128,7 +171,9 @@ export function TrackingCostReview({
<Button
disabled={
!cost ||
- estimate.isPlaceholderData ||
+ // Approve only the current price, not the preloaded one
+ // still being refreshed.
+ estimate.isFetching ||
start.isPending ||
cost.observations === 0
}
diff --git a/src/client/features/ai-visibility/VisibilityTrend.tsx b/src/client/features/ai-visibility/VisibilityTrend.tsx
index 904481a9..7d50550b 100644
--- a/src/client/features/ai-visibility/VisibilityTrend.tsx
+++ b/src/client/features/ai-visibility/VisibilityTrend.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { useQuery } from "@tanstack/react-query";
+import { queryOptions, useQuery } from "@tanstack/react-query";
import { Info, TriangleAlert } from "lucide-react";
import { cn } from "cn";
import { SegmentedToggle } from "@/client/components/SegmentedToggle";
@@ -42,13 +42,18 @@ function notice(trend: AiTrend) {
}
}
-/** The trend panel inside the Prompt tracking card, laid out like rank tracking's overview. */
-export function VisibilityTrend({ projectId }: { projectId: string }) {
- const [days, setDays] = useState<7 | 28 | 90>(7);
- const query = useQuery({
+type AiTrendDays = 7 | 28 | 90;
+
+export const aiTrendQueryOptions = (projectId: string, days: AiTrendDays) =>
+ queryOptions({
queryKey: [...aiVisibilityKey(projectId), "results", "trend", days],
queryFn: () => getAiVisibilityTrend({ data: { projectId, days } }),
});
+
+/** The trend panel inside the Prompt tracking card, laid out like rank tracking's overview. */
+export function VisibilityTrend({ projectId }: { projectId: string }) {
+ const [days, setDays] = useState<AiTrendDays>(7);
+ const query = useQuery(aiTrendQueryOptions(projectId, days));
const trend = query.data;
const message = trend && notice(trend);
// Incomplete collection and a changed scope need attention; missing history does not.
diff --git a/src/client/features/ai-visibility/shared.tsx b/src/client/features/ai-visibility/shared.tsx
index f37c80b0..38672027 100644
--- a/src/client/features/ai-visibility/shared.tsx
+++ b/src/client/features/ai-visibility/shared.tsx
@@ -1,6 +1,6 @@
import { useEffect } from "react";
import { Link } from "@tanstack/react-router";
-import { useQuery, useQueryClient } from "@tanstack/react-query";
+import { queryOptions, useQuery, useQueryClient } from "@tanstack/react-query";
import { Loader2 } from "lucide-react";
import { QueryError } from "@/client/components/QueryState";
import { Spinner } from "@/client/components/Spinner";
@@ -8,6 +8,7 @@ import { Badge } from "@/client/components/ui/badge";
import { Button } from "@/client/components/ui/button";
import { Progress } from "@/client/components/ui/progress";
import {
+ getAiResearchSetup,
getAiVisibilityRun,
getAiVisibilityTracker,
getAiVisibilityResults,
@@ -20,7 +21,7 @@ export const aiVisibilityKey = (projectId: string) => [
];
/** Read the full bounded result set for prompt inventory and history. */
-export async function fetchAllAiVisibilityResults(
+async function fetchAllAiVisibilityResults(
input: Omit<
Parameters<typeof getAiVisibilityResults>[0]["data"],
"cursor" | "limit" | "branded"
@@ -40,12 +41,53 @@ export async function fetchAllAiVisibilityResults(
return { ...first, rows };
}
-export function useAiVisibilityTracker(projectId: string) {
- return useQuery({
+export const aiTrackerQueryOptions = (projectId: string) =>
+ queryOptions({
queryKey: [...aiVisibilityKey(projectId), "tracker"],
queryFn: () => getAiVisibilityTracker({ data: { projectId } }),
staleTime: 0,
});
+
+export const aiResearchSetupQueryOptions = (projectId: string) =>
+ queryOptions({
+ queryKey: [...aiVisibilityKey(projectId), "researchSetup"],
+ queryFn: () => getAiResearchSetup({ data: { projectId } }),
+ refetchInterval: (query) =>
+ query.state.data?.status === "running" ? 3000 : false,
+ });
+
+/** Every answer in a run, so each prompt can show its per-engine result. */
+export const aiRunResultsQueryOptions = (
+ projectId: string,
+ runId: string | undefined,
+) =>
+ queryOptions({
+ queryKey: [...aiVisibilityKey(projectId), "results", "all", runId],
+ queryFn: async () => {
+ const result = await fetchAllAiVisibilityResults({ projectId, runId });
+ return result.rows;
+ },
+ enabled: Boolean(runId),
+ });
+
+export const aiPromptHistoryQueryOptions = (
+ projectId: string,
+ promptId: string,
+) =>
+ queryOptions({
+ queryKey: [...aiVisibilityKey(projectId), "results", "history", promptId],
+ // Read all pages of the latest 50 runs so engine ordering cannot hide
+ // a newer execution from the selector.
+ queryFn: () =>
+ fetchAllAiVisibilityResults({
+ projectId,
+ promptId,
+ includeHistory: true,
+ }),
+ });
+
+export function useAiVisibilityTracker(projectId: string) {
+ return useQuery(aiTrackerQueryOptions(projectId));
}
export function useAiRunProgress(projectId: string, initialRun: AiRun | null) {
diff --git a/src/routes/_app/p/$projectId/ai-visibility.tsx b/src/routes/_app/p/$projectId/ai-visibility.tsx
index a7d0f963..5c941662 100644
--- a/src/routes/_app/p/$projectId/ai-visibility.tsx
+++ b/src/routes/_app/p/$projectId/ai-visibility.tsx
@@ -1,8 +1,22 @@
import { createFileRoute, Outlet } from "@tanstack/react-router";
import { AiResearchSetupGate } from "@/client/features/ai-visibility/AiResearchSetupGate";
+import {
+ aiResearchSetupQueryOptions,
+ aiTrackerQueryOptions,
+} from "@/client/features/ai-visibility/shared";
import { ProjectWebsiteGate } from "@/client/features/projects/ProjectWebsiteGate";
+import { queryClient } from "@/client/tanstack-db/queryClient";
export const Route = createFileRoute("/_app/p/$projectId/ai-visibility")({
+ // The setup gate below mounts only after the website gate, and each page
+ // here only after setup. Start setup and the tracker every page reads
+ // together on link intent and on a full load, without holding up navigation.
+ loader: ({ params }) => {
+ void queryClient.prefetchQuery(
+ aiResearchSetupQueryOptions(params.projectId),
+ );
+ void queryClient.prefetchQuery(aiTrackerQueryOptions(params.projectId));
+ },
component: AiVisibilityLayout,
});
diff --git a/src/routes/_app/p/$projectId/ai-visibility/index.tsx b/src/routes/_app/p/$projectId/ai-visibility/index.tsx
index 7b83f96a..ccb5fb33 100644
--- a/src/routes/_app/p/$projectId/ai-visibility/index.tsx
+++ b/src/routes/_app/p/$projectId/ai-visibility/index.tsx
@@ -2,6 +2,12 @@ import { createFileRoute } from "@tanstack/react-router";
import { z } from "zod";
import { PromptTrackingPage } from "@/client/features/ai-visibility/PromptTrackingPage";
import { PROMPT_TRACKING_TABS } from "@/client/features/ai-visibility/PromptTrackingTabs";
+import {
+ aiRunResultsQueryOptions,
+ aiTrackerQueryOptions,
+} from "@/client/features/ai-visibility/shared";
+import { aiTrendQueryOptions } from "@/client/features/ai-visibility/VisibilityTrend";
+import { queryClient } from "@/client/tanstack-db/queryClient";
const tabs = PROMPT_TRACKING_TABS.map((item) => item.value);
@@ -9,6 +15,21 @@ export const Route = createFileRoute("/_app/p/$projectId/ai-visibility/")({
validateSearch: z.object({
tab: z.enum(tabs).optional().catch(undefined),
}),
+ loader: ({ params: { projectId } }) => {
+ void queryClient.prefetchQuery(aiTrendQueryOptions(projectId, 7));
+ // The prompt table reads the latest run's answers, known from a fresh
+ // tracker: a cached one can predate the latest run.
+ void queryClient
+ .fetchQuery(aiTrackerQueryOptions(projectId))
+ .then((state) => {
+ const runId = state.recentRuns[0]?.id;
+ if (runId)
+ return queryClient.prefetchQuery(
+ aiRunResultsQueryOptions(projectId, runId),
+ );
+ })
+ .catch(() => undefined);
+ },
component: PromptTrackingRoute,
});
diff --git a/src/routes/_app/p/$projectId/ai-visibility/prompts/$promptId.tsx b/src/routes/_app/p/$projectId/ai-visibility/prompts/$promptId.tsx
index ff654818..8f73ac59 100644
--- a/src/routes/_app/p/$projectId/ai-visibility/prompts/$promptId.tsx
+++ b/src/routes/_app/p/$projectId/ai-visibility/prompts/$promptId.tsx
@@ -1,9 +1,18 @@
import { createFileRoute } from "@tanstack/react-router";
import { PromptHistoryPage } from "@/client/features/ai-visibility/PromptHistoryPage";
+import { aiPromptHistoryQueryOptions } from "@/client/features/ai-visibility/shared";
+import { queryClient } from "@/client/tanstack-db/queryClient";
export const Route = createFileRoute(
"/_app/p/$projectId/ai-visibility/prompts/$promptId",
-)({ component: AiPromptHistoryRoute });
+)({
+ loader: ({ params }) => {
+ void queryClient.prefetchQuery(
+ aiPromptHistoryQueryOptions(params.projectId, params.promptId),
+ );
+ },
+ component: AiPromptHistoryRoute,
+});
function AiPromptHistoryRoute() {
const { projectId, promptId } = Route.useParams();
diff --git a/src/routes/_app/p/$projectId/prompt-explorer.tsx b/src/routes/_app/p/$projectId/prompt-explorer.tsx
index bec27353..431b9a2c 100644
--- a/src/routes/_app/p/$projectId/prompt-explorer.tsx
+++ b/src/routes/_app/p/$projectId/prompt-explorer.tsx
@@ -2,7 +2,9 @@ import { useMemo } from "react";
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { PromptExplorerPage } from "@/client/features/ai-search/PromptExplorerPage";
import { AiResearchSetupGate } from "@/client/features/ai-visibility/AiResearchSetupGate";
+import { aiResearchSetupQueryOptions } from "@/client/features/ai-visibility/shared";
import { ProjectWebsiteGate } from "@/client/features/projects/ProjectWebsiteGate";
+import { queryClient } from "@/client/tanstack-db/queryClient";
import {
promptExplorerSearchSchema,
type PromptExplorerModel,
@@ -10,6 +12,12 @@ import {
export const Route = createFileRoute("/_app/p/$projectId/prompt-explorer")({
validateSearch: promptExplorerSearchSchema,
+ // Start the setup gate's read on link intent, as AI visibility does.
+ loader: ({ params }) => {
+ void queryClient.prefetchQuery(
+ aiResearchSetupQueryOptions(params.projectId),
+ );
+ },
component: PromptExplorerRoute,
});