Skip to content

Open source alternative to Semrush and Ahrefs

Show loading and retryable errors instead of stuck spinners and blank screens (EVE-277) (#683)

Carter Smithff9b869849cd
diff --git a/src/client/components/QueryState.test.ts b/src/client/components/QueryState.test.ts
new file mode 100644
index 00000000..fccb65d2
--- /dev/null
+++ b/src/client/components/QueryState.test.ts
@@ -0,0 +1,43 @@
+import { renderToStaticMarkup } from "react-dom/server";
+import type { UseQueryResult } from "@tanstack/react-query";
+import { describe, expect, it } from "vitest";
+import { QueryState } from "./QueryState";
+
+function renderQueryState(query: Partial<UseQueryResult<string>>) {
+ // QueryState has no hooks, so calling it directly renders the same tree.
+ return renderToStaticMarkup(
+ QueryState({
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- only the fields QueryState reads
+ query: query as UseQueryResult<string>,
+ errorFallback: "Failed to load",
+ children: (data) => `content:${data}`,
+ }),
+ );
+}
+
+describe("QueryState", () => {
+ it("replaces the content with a retryable error when the first load fails", () => {
+ const markup = renderQueryState({
+ isPending: false,
+ isError: true,
+ error: new Error("Server down"),
+ data: undefined,
+ });
+
+ expect(markup).toContain("Server down");
+ expect(markup).toContain("Try again");
+ expect(markup).not.toContain("content:");
+ });
+
+ it("keeps loaded content on screen when a refetch fails", () => {
+ const markup = renderQueryState({
+ isPending: false,
+ isError: true,
+ error: new Error("Server down"),
+ data: "rows",
+ });
+
+ expect(markup).toContain("Server down");
+ expect(markup).toContain("content:rows");
+ });
+});
diff --git a/src/client/components/QueryState.tsx b/src/client/components/QueryState.tsx
new file mode 100644
index 00000000..cee15c30
--- /dev/null
+++ b/src/client/components/QueryState.tsx
@@ -0,0 +1,73 @@
+import type { ReactNode } from "react";
+import type { UseQueryResult } from "@tanstack/react-query";
+import { getStandardErrorMessage } from "@/client/lib/error-messages";
+import { PageLoading } from "./Spinner";
+
+/** A load failure with a retry button. The message goes through `getStandardErrorMessage`. */
+export function QueryError({
+ error,
+ fallback,
+ onRetry,
+ isRetrying = false,
+}: {
+ /** Omit to always show `fallback`, for errors the page words itself. */
+ error?: unknown;
+ /** Shown when the error has no message of its own. */
+ fallback: string;
+ onRetry?: () => void;
+ isRetrying?: boolean;
+}) {
+ return (
+ <div role="alert" className="alert alert-error">
+ <span className="text-sm">
+ {getStandardErrorMessage(error, fallback)}
+ </span>
+ {onRetry ? (
+ <button
+ type="button"
+ className="btn btn-sm"
+ onClick={onRetry}
+ disabled={isRetrying}
+ >
+ {isRetrying ? "Retrying…" : "Try again"}
+ </button>
+ ) : null}
+ </div>
+ );
+}
+
+/**
+ * Loading, error with retry, or content for one query. A failed refetch keeps
+ * the loaded content on screen, with the error above it.
+ */
+export function QueryState<TData>({
+ query,
+ errorFallback,
+ loading = <PageLoading />,
+ children,
+}: {
+ query: UseQueryResult<TData>;
+ errorFallback: string;
+ loading?: ReactNode;
+ children: (data: TData) => ReactNode;
+}) {
+ if (query.isPending) return loading;
+
+ const error = query.isError ? (
+ <QueryError
+ error={query.error}
+ fallback={errorFallback}
+ onRetry={() => void query.refetch()}
+ isRetrying={query.isFetching}
+ />
+ ) : null;
+
+ if (query.data === undefined) return error;
+
+ return (
+ <>
+ {error}
+ {children(query.data)}
+ </>
+ );
+}
diff --git a/src/client/components/Skeleton.tsx b/src/client/components/Skeleton.tsx
new file mode 100644
index 00000000..8f0d586e
--- /dev/null
+++ b/src/client/components/Skeleton.tsx
@@ -0,0 +1,4 @@
+/** A placeholder block with the shape of content that has not loaded yet. Size it with `className`. */
+export function Skeleton({ className = "" }: { className?: string }) {
+ return <div aria-hidden className={`skeleton ${className}`} />;
+}
diff --git a/src/client/components/Spinner.tsx b/src/client/components/Spinner.tsx
new file mode 100644
index 00000000..cadcc31d
--- /dev/null
+++ b/src/client/components/Spinner.tsx
@@ -0,0 +1,41 @@
+import { Loader2 } from "lucide-react";
+
+export function Spinner({
+ size = "md",
+ label,
+ className = "",
+}: {
+ size?: "sm" | "md";
+ /** Shown beside the spinner, e.g. "Checking…". Screen readers get "Loading" without it. */
+ label?: string;
+ className?: string;
+}) {
+ return (
+ <span
+ role="status"
+ className={`inline-flex items-center gap-2 text-sm text-base-content/60 ${className}`}
+ >
+ <Loader2
+ aria-hidden
+ className={`${size === "sm" ? "size-4" : "size-6"} shrink-0 animate-spin`}
+ />
+ {label ? <span>{label}</span> : <span className="sr-only">Loading</span>}
+ </span>
+ );
+}
+
+/** The centered spinner for a page or section whose data has not arrived. */
+export function PageLoading({
+ fullScreen = false,
+}: {
+ /** Fill the viewport, for layouts that render before any app chrome. */
+ fullScreen?: boolean;
+}) {
+ return (
+ <div
+ className={`flex items-center justify-center ${fullScreen ? "min-h-dvh" : "py-10"}`}
+ >
+ <Spinner />
+ </div>
+ );
+}
diff --git a/src/client/features/ai-search/components/AiSearchLoadingState.tsx b/src/client/features/ai-search/components/AiSearchLoadingState.tsx
index 89253c4a..cbcc6a8b 100644
--- a/src/client/features/ai-search/components/AiSearchLoadingState.tsx
+++ b/src/client/features/ai-search/components/AiSearchLoadingState.tsx
@@ -1,25 +1,27 @@
+import { Skeleton } from "@/client/components/Skeleton";
+
export function AiSearchLoadingState() {
return (
<div className="space-y-8" aria-busy>
<div className="grid grid-cols-1 gap-px overflow-hidden rounded-xl border border-base-300 bg-base-300 sm:grid-cols-3">
{Array.from({ length: 3 }).map((_, index) => (
<div key={index} className="space-y-2 bg-base-100 p-5">
- <div className="skeleton h-3 w-24" />
- <div className="skeleton h-8 w-32" />
- <div className="skeleton h-3 w-40" />
+ <Skeleton className="h-3 w-24" />
+ <Skeleton className="h-8 w-32" />
+ <Skeleton className="h-3 w-40" />
</div>
))}
</div>
<div className="space-y-3">
- <div className="skeleton h-4 w-32" />
+ <Skeleton className="h-4 w-32" />
<div className="space-y-2 rounded-lg border border-base-300 p-4">
{Array.from({ length: 6 }).map((_, index) => (
<div key={index} className="grid grid-cols-6 gap-3">
- <div className="skeleton col-span-3 h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
+ <Skeleton className="col-span-3 h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
</div>
))}
</div>
diff --git a/src/client/features/ai-search/components/PromptExplorerLoadingState.tsx b/src/client/features/ai-search/components/PromptExplorerLoadingState.tsx
index 9e1e39d3..84aa02e0 100644
--- a/src/client/features/ai-search/components/PromptExplorerLoadingState.tsx
+++ b/src/client/features/ai-search/components/PromptExplorerLoadingState.tsx
@@ -1,3 +1,5 @@
+import { Skeleton } from "@/client/components/Skeleton";
+
type Props = {
modelCount: number;
};
@@ -13,17 +15,17 @@ export function PromptExplorerLoadingState({ modelCount }: Props) {
>
<header className="flex items-center justify-between border-b border-base-200 bg-base-200/40 px-5 py-3">
<div className="flex items-center gap-2">
- <div className="skeleton size-2 rounded-full" />
- <div className="skeleton h-4 w-20" />
- <div className="skeleton h-3 w-32" />
+ <Skeleton className="size-2 rounded-full" />
+ <Skeleton className="h-4 w-20" />
+ <Skeleton className="h-3 w-32" />
</div>
- <div className="skeleton h-3 w-16" />
+ <Skeleton className="h-3 w-16" />
</header>
<div className="space-y-2 px-5 py-5">
- <div className="skeleton h-3 w-full" />
- <div className="skeleton h-3 w-11/12" />
- <div className="skeleton h-3 w-10/12" />
- <div className="skeleton h-3 w-9/12" />
+ <Skeleton className="h-3 w-full" />
+ <Skeleton className="h-3 w-11/12" />
+ <Skeleton className="h-3 w-10/12" />
+ <Skeleton className="h-3 w-9/12" />
</div>
</article>
))}
diff --git a/src/client/features/backlinks/BacklinksPageSections.tsx b/src/client/features/backlinks/BacklinksPageSections.tsx
index 5ac67e37..46db3c58 100644
--- a/src/client/features/backlinks/BacklinksPageSections.tsx
+++ b/src/client/features/backlinks/BacklinksPageSections.tsx
@@ -26,6 +26,7 @@ import {
type BacklinksTab,
} from "@/types/schemas/backlinks";
import type { ResearchScope } from "@/shared/researchScope";
+import { Skeleton } from "@/client/components/Skeleton";
const BACKLINKS_RESULTS_TABS: Array<{
tab: BacklinksSearchState["tab"];
@@ -355,9 +356,9 @@ function TabLoadingState({ label }: { label: string }) {
return (
<div className="space-y-3 py-2">
<p className="text-sm text-base-content/60">{label}...</p>
- <div className="skeleton h-10 w-full" />
- <div className="skeleton h-10 w-full" />
- <div className="skeleton h-10 w-full" />
+ <Skeleton className="h-10 w-full" />
+ <Skeleton className="h-10 w-full" />
+ <Skeleton className="h-10 w-full" />
</div>
);
}
diff --git a/src/client/features/backlinks/BacklinksPageStates.tsx b/src/client/features/backlinks/BacklinksPageStates.tsx
index b0f08d1e..b890485e 100644
--- a/src/client/features/backlinks/BacklinksPageStates.tsx
+++ b/src/client/features/backlinks/BacklinksPageStates.tsx
@@ -1,4 +1,5 @@
import { ShieldAlert } from "lucide-react";
+import { Skeleton } from "@/client/components/Skeleton";
export function BacklinksLoadingState() {
return (
@@ -7,8 +8,8 @@ export function BacklinksLoadingState() {
{Array.from({ length: 8 }).map((_, index) => (
<div key={index} className="card bg-base-100 border border-base-300">
<div className="card-body gap-3 p-4">
- <div className="skeleton h-3 w-24" />
- <div className="skeleton h-8 w-28" />
+ <Skeleton className="h-3 w-24" />
+ <Skeleton className="h-8 w-28" />
</div>
</div>
))}
@@ -17,16 +18,16 @@ export function BacklinksLoadingState() {
{Array.from({ length: 2 }).map((_, index) => (
<div key={index} className="card bg-base-100 border border-base-300">
<div className="card-body gap-3">
- <div className="skeleton h-4 w-32" />
- <div className="skeleton h-64 w-full" />
+ <Skeleton className="h-4 w-32" />
+ <Skeleton className="h-64 w-full" />
</div>
</div>
))}
</div>
<div className="card bg-base-100 border border-base-300">
<div className="card-body gap-3">
- <div className="skeleton h-8 w-60" />
- <div className="skeleton h-80 w-full" />
+ <Skeleton className="h-8 w-60" />
+ <Skeleton className="h-80 w-full" />
</div>
</div>
</div>
diff --git a/src/client/features/billing/BillingFeatureBreakdown.tsx b/src/client/features/billing/BillingFeatureBreakdown.tsx
index 2ad4f750..3435f7ce 100644
--- a/src/client/features/billing/BillingFeatureBreakdown.tsx
+++ b/src/client/features/billing/BillingFeatureBreakdown.tsx
@@ -13,6 +13,7 @@ import {
getBillingUsageEvents,
type BillingUsageEvent,
} from "@/serverFunctions/billing";
+import { Skeleton } from "@/client/components/Skeleton";
const BILLING_USAGE_FEATURE_IDS: string[] = [
AUTUMN_SEO_DATA_BALANCE_FEATURE_ID,
@@ -156,7 +157,7 @@ export function BillingFeatureBreakdown() {
{eventsQuery.isLoading ? (
<div className="space-y-3">
{[0, 1, 2, 3].map((i) => (
- <div key={i} className="skeleton h-4 w-full" />
+ <Skeleton key={i} className="h-4 w-full" />
))}
</div>
) : rows.length === 0 ? (
diff --git a/src/client/features/dashboard/DashboardCards.tsx b/src/client/features/dashboard/DashboardCards.tsx
index 6687872c..ee314e18 100644
--- a/src/client/features/dashboard/DashboardCards.tsx
+++ b/src/client/features/dashboard/DashboardCards.tsx
@@ -23,6 +23,7 @@ import type {
DashboardAuditSummary,
DashboardBacklinkSummary,
} from "@/server/features/dashboard/services/DashboardService";
+import { Skeleton } from "@/client/components/Skeleton";
// Plain string-keyed view of the registry: issue types from the DB are not
// statically guaranteed to be registry keys.
@@ -75,7 +76,7 @@ export function GscCard({
{reportQuery.isPending ? (
<div className="grid grid-cols-2 gap-3" aria-busy>
{Array.from({ length: 4 }, (_, i) => (
- <div key={i} className="skeleton h-20" />
+ <Skeleton key={i} className="h-20" />
))}
</div>
) : reportQuery.isError ? (
@@ -218,7 +219,7 @@ export function BacklinkPulseCard({
<CardShell title="Backlink pulse" stamp="Taking your first snapshot…">
<div className="grid grid-cols-2 gap-3" aria-busy>
{Array.from({ length: 4 }, (_, i) => (
- <div key={i} className="skeleton h-20" />
+ <Skeleton key={i} className="h-20" />
))}
</div>
</CardShell>
diff --git a/src/client/features/dashboard/DashboardPage.tsx b/src/client/features/dashboard/DashboardPage.tsx
index 636d186e..6002f4fe 100644
--- a/src/client/features/dashboard/DashboardPage.tsx
+++ b/src/client/features/dashboard/DashboardPage.tsx
@@ -15,6 +15,7 @@ import {
getDashboardOverview,
refreshDashboardBacklinkSnapshot,
} from "@/serverFunctions/dashboard";
+import { Skeleton } from "@/client/components/Skeleton";
export function DashboardPage({ projectId }: { projectId: string }) {
const queryClient = useQueryClient();
@@ -71,11 +72,11 @@ export function DashboardPage({ projectId }: { projectId: string }) {
className="mx-auto flex max-w-5xl flex-col gap-5 px-4 py-4 md:px-6 md:py-6"
aria-busy
>
- <div className="skeleton h-8 w-52" />
- <div className="skeleton h-36" />
+ <Skeleton className="h-8 w-52" />
+ <Skeleton className="h-36" />
<div className="grid gap-5 lg:grid-cols-2">
- <div className="skeleton h-44" />
- <div className="skeleton h-44" />
+ <Skeleton className="h-44" />
+ <Skeleton className="h-44" />
</div>
</div>
);
diff --git a/src/client/features/dashboard/DashboardSetupAction.tsx b/src/client/features/dashboard/DashboardSetupAction.tsx
index 7dc9924a..c904e548 100644
--- a/src/client/features/dashboard/DashboardSetupAction.tsx
+++ b/src/client/features/dashboard/DashboardSetupAction.tsx
@@ -22,6 +22,7 @@ import { getProjects, setProjectWebsite } from "@/serverFunctions/projects";
import { markDashboardCompetitorClicked } from "@/serverFunctions/dashboard";
import type { DashboardSetupStep } from "@/types/schemas/dashboard";
import { parseResearchTarget } from "@/shared/researchScope";
+import { Skeleton } from "@/client/components/Skeleton";
const projectPrompt = `Use OpenSEO to set up a separate project for each website below. List my existing projects first and reuse matches so you don’t create duplicates. Set the country and language for each site, and ask me about anything missing.
@@ -65,7 +66,7 @@ export function DashboardSetupAction({
{getStandardErrorMessage(projects.error)}
</p>
) : (
- <div className="skeleton h-36" aria-busy />
+ <Skeleton className="h-36" />
);
if (step === "mcp")
return (
diff --git a/src/client/features/dashboard/Ga4Card.tsx b/src/client/features/dashboard/Ga4Card.tsx
index 7590410e..86abb8b5 100644
--- a/src/client/features/dashboard/Ga4Card.tsx
+++ b/src/client/features/dashboard/Ga4Card.tsx
@@ -20,6 +20,7 @@ import {
formatCtr,
} from "@/client/features/search-performance/SearchPerformanceColumns";
import { getGa4DashboardReport } from "@/serverFunctions/ga4";
+import { Skeleton } from "@/client/components/Skeleton";
function formatTrendDay(date: string): string {
// Construct in local time: Date.parse("2026-08-01") is UTC midnight, which
@@ -106,10 +107,10 @@ export function Ga4Card({
<div className="space-y-3" aria-busy>
<div className="grid grid-cols-2 gap-3">
{Array.from({ length: 4 }, (_, i) => (
- <div key={i} className="skeleton h-16" />
+ <Skeleton key={i} className="h-16" />
))}
</div>
- <div className="skeleton h-24" />
+ <Skeleton className="h-24" />
</div>
) : reportQuery.isError ? (
<p className="text-sm text-base-content/60">
diff --git a/src/client/features/domain/components/DomainOverviewLoadingState.tsx b/src/client/features/domain/components/DomainOverviewLoadingState.tsx
index 30006fce..e0ebf73d 100644
--- a/src/client/features/domain/components/DomainOverviewLoadingState.tsx
+++ b/src/client/features/domain/components/DomainOverviewLoadingState.tsx
@@ -1,17 +1,19 @@
+import { Skeleton } from "@/client/components/Skeleton";
+
export function DomainOverviewLoadingState() {
return (
<div className="space-y-4" aria-busy>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
<div className="card bg-base-100 border border-base-300">
<div className="card-body p-4 space-y-2">
- <div className="skeleton h-3 w-36" />
- <div className="skeleton h-8 w-44" />
+ <Skeleton className="h-3 w-36" />
+ <Skeleton className="h-8 w-44" />
</div>
</div>
<div className="card bg-base-100 border border-base-300">
<div className="card-body p-4 space-y-2">
- <div className="skeleton h-3 w-32" />
- <div className="skeleton h-8 w-40" />
+ <Skeleton className="h-3 w-32" />
+ <Skeleton className="h-8 w-40" />
</div>
</div>
</div>
@@ -19,18 +21,18 @@ export function DomainOverviewLoadingState() {
<div className="card bg-base-100 border border-base-300">
<div className="card-body gap-3">
<div className="flex items-center justify-between">
- <div className="skeleton h-8 w-48" />
- <div className="skeleton h-8 w-60" />
+ <Skeleton className="h-8 w-48" />
+ <Skeleton className="h-8 w-60" />
</div>
- <div className="skeleton h-9 w-64" />
+ <Skeleton className="h-9 w-64" />
<div className="space-y-2">
{Array.from({ length: 8 }).map((_, index) => (
<div key={index} className="grid grid-cols-7 gap-3">
- <div className="skeleton h-4 col-span-2" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4 col-span-2" />
+ <Skeleton className="h-4 col-span-2" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4 col-span-2" />
</div>
))}
</div>
diff --git a/src/client/features/domain/components/TableLoadingRows.tsx b/src/client/features/domain/components/TableLoadingRows.tsx
index 32b269fb..c6da3599 100644
--- a/src/client/features/domain/components/TableLoadingRows.tsx
+++ b/src/client/features/domain/components/TableLoadingRows.tsx
@@ -1,13 +1,15 @@
+import { Skeleton } from "@/client/components/Skeleton";
+
export function TableLoadingRows() {
return (
<div className="space-y-3 py-4" aria-busy>
{Array.from({ length: 8 }).map((_, index) => (
<div key={index} className="grid grid-cols-6 gap-3">
- <div className="skeleton h-4 col-span-2" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
+ <Skeleton className="h-4 col-span-2" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
</div>
))}
</div>
diff --git a/src/client/features/integrations/GooglePropertyPicker.tsx b/src/client/features/integrations/GooglePropertyPicker.tsx
index a75ba729..0405bce0 100644
--- a/src/client/features/integrations/GooglePropertyPicker.tsx
+++ b/src/client/features/integrations/GooglePropertyPicker.tsx
@@ -1,4 +1,6 @@
import { GoogleAccountRemovalDialog } from "@/client/features/integrations/GoogleAccountRemovalDialog";
+import { QueryError } from "@/client/components/QueryState";
+import { Spinner } from "@/client/components/Spinner";
import {
useId,
useRef,
@@ -178,24 +180,16 @@ export function GooglePropertyPicker({
</label>
<div className="max-h-72 overflow-y-auto overscroll-contain p-1.5">
{loading ? (
- <p
- role="status"
- className="flex items-center gap-2 p-3 text-sm text-base-content/60"
- >
- <span className="loading loading-spinner loading-xs" />
- Loading properties…
- </p>
+ <Spinner
+ size="sm"
+ label="Loading properties…"
+ className="p-3"
+ />
) : error ? (
- <div role="alert" className="p-3 text-sm">
- <p className="text-error">Couldn't load properties.</p>
- <button
- type="button"
- className="btn btn-ghost btn-sm mt-1"
- onClick={onRetry}
- >
- Try again
- </button>
- </div>
+ <QueryError
+ fallback="Couldn't load properties."
+ onRetry={onRetry}
+ />
) : (
<>
{filtered.map((account) => (
diff --git a/src/client/features/keywords/page/KeywordResearchLoadingState.tsx b/src/client/features/keywords/page/KeywordResearchLoadingState.tsx
index c666019e..a9e63651 100644
--- a/src/client/features/keywords/page/KeywordResearchLoadingState.tsx
+++ b/src/client/features/keywords/page/KeywordResearchLoadingState.tsx
@@ -1,15 +1,17 @@
+import { Skeleton } from "@/client/components/Skeleton";
+
export function KeywordResearchLoadingState() {
return (
<div className="flex-1 w-full">
<div className="hidden md:flex h-full gap-4">
<div className="flex-1 flex flex-col min-w-0 gap-2">
<div className="rounded-xl border border-base-300 bg-base-100 p-4">
- <div className="skeleton h-5 w-56" />
+ <Skeleton className="h-5 w-56" />
</div>
<div className="flex-1 rounded-xl border border-base-300 bg-base-100 overflow-hidden">
<div className="border-b border-base-300 px-4 py-3 flex items-center gap-3">
- <div className="skeleton h-8 w-24" />
- <div className="skeleton h-4 w-40" />
+ <Skeleton className="h-8 w-24" />
+ <Skeleton className="h-4 w-40" />
</div>
<div className="p-4 space-y-3">
{Array.from({ length: 10 }).map((_, index) => (
@@ -17,12 +19,12 @@ export function KeywordResearchLoadingState() {
key={index}
className="grid grid-cols-[24px_minmax(0,1fr)_64px_56px_48px_40px] items-center gap-3"
>
- <div className="skeleton h-3 w-3" />
- <div className="skeleton h-4 w-10/12" />
- <div className="skeleton h-3 w-12 justify-self-end" />
- <div className="skeleton h-3 w-10 justify-self-end" />
- <div className="skeleton h-3 w-10 justify-self-end" />
- <div className="skeleton h-6 w-6 rounded-full justify-self-end" />
+ <Skeleton className="h-3 w-3" />
+ <Skeleton className="h-4 w-10/12" />
+ <Skeleton className="h-3 w-12 justify-self-end" />
+ <Skeleton className="h-3 w-10 justify-self-end" />
+ <Skeleton className="h-3 w-10 justify-self-end" />
+ <Skeleton className="h-6 w-6 rounded-full justify-self-end" />
</div>
))}
</div>
@@ -30,16 +32,16 @@ export function KeywordResearchLoadingState() {
</div>
<div className="flex-1 flex flex-col min-w-0 gap-2">
<div className="rounded-xl border border-base-300 bg-base-100 p-4 space-y-3">
- <div className="skeleton h-4 w-36" />
- <div className="skeleton h-56 w-full" />
+ <Skeleton className="h-4 w-36" />
+ <Skeleton className="h-56 w-full" />
</div>
<div className="flex-1 rounded-xl border border-base-300 bg-base-100 p-4 space-y-3">
- <div className="skeleton h-4 w-44" />
+ <Skeleton className="h-4 w-44" />
{Array.from({ length: 6 }).map((_, index) => (
<div key={index} className="grid grid-cols-[24px_1fr_72px] gap-2">
- <div className="skeleton h-3 w-4" />
- <div className="skeleton h-3 w-10/12" />
- <div className="skeleton h-3 w-12 justify-self-end" />
+ <Skeleton className="h-3 w-4" />
+ <Skeleton className="h-3 w-10/12" />
+ <Skeleton className="h-3 w-12 justify-self-end" />
</div>
))}
</div>
@@ -48,8 +50,8 @@ export function KeywordResearchLoadingState() {
<div className="md:hidden space-y-3">
<div className="rounded-xl border border-base-300 bg-base-100 p-4 space-y-3">
- <div className="skeleton h-8 w-full" />
- <div className="skeleton h-8 w-2/3" />
+ <Skeleton className="h-8 w-full" />
+ <Skeleton className="h-8 w-2/3" />
</div>
<div className="rounded-xl border border-base-300 bg-base-100 p-4 space-y-2">
{Array.from({ length: 8 }).map((_, index) => (
@@ -57,11 +59,11 @@ export function KeywordResearchLoadingState() {
key={index}
className="space-y-2 rounded-lg border border-base-300 p-3"
>
- <div className="skeleton h-4 w-9/12" />
+ <Skeleton className="h-4 w-9/12" />
<div className="grid grid-cols-3 gap-2">
- <div className="skeleton h-3 w-full" />
- <div className="skeleton h-3 w-full" />
- <div className="skeleton h-3 w-full" />
+ <Skeleton className="h-3 w-full" />
+ <Skeleton className="h-3 w-full" />
+ <Skeleton className="h-3 w-full" />
</div>
</div>
))}
diff --git a/src/client/features/lighthouse/issues/LighthouseIssuesParts.tsx b/src/client/features/lighthouse/issues/LighthouseIssuesParts.tsx
index d6a641f7..4925bfd2 100644
--- a/src/client/features/lighthouse/issues/LighthouseIssuesParts.tsx
+++ b/src/client/features/lighthouse/issues/LighthouseIssuesParts.tsx
@@ -23,6 +23,7 @@ import { categoryTabs } from "./types";
export function LighthouseIssuesHeader({
backLabel,
onBack,
+ isLoading,
scannedAt,
finalUrl,
scores,
@@ -31,6 +32,7 @@ export function LighthouseIssuesHeader({
}: {
backLabel: string;
onBack: () => void;
+ isLoading: boolean;
scannedAt?: string;
finalUrl?: string;
scores?: LighthouseScores | null;
@@ -46,7 +48,9 @@ export function LighthouseIssuesHeader({
<span className="text-xs text-base-content/60">
{scannedAt
? `Scanned ${new Date(scannedAt).toLocaleString()}`
- : "Reading latest issues..."}
+ : isLoading
+ ? "Reading latest issues..."
+ : null}
</span>
</div>
@@ -55,7 +59,7 @@ export function LighthouseIssuesHeader({
<div className="space-y-1">
<h1 className="text-2xl font-semibold">Lighthouse Issues</h1>
<p className="text-sm text-base-content/70 break-all">
- {finalUrl ?? "Loading URL..."}
+ {finalUrl ?? (isLoading ? "Loading URL..." : null)}
</p>
</div>
<LighthouseIssuesSummary scores={scores} metrics={metrics} />
diff --git a/src/client/features/lighthouse/issues/LighthouseIssuesScreen.tsx b/src/client/features/lighthouse/issues/LighthouseIssuesScreen.tsx
index 342a3845..df8ca841 100644
--- a/src/client/features/lighthouse/issues/LighthouseIssuesScreen.tsx
+++ b/src/client/features/lighthouse/issues/LighthouseIssuesScreen.tsx
@@ -1,12 +1,13 @@
import { useMutation, useQuery } from "@tanstack/react-query";
-import { AlertCircle, TriangleAlert } from "lucide-react";
+import { TriangleAlert } from "lucide-react";
import { toast } from "sonner";
import {
exportAuditLighthouseIssues,
getAuditLighthouseIssues,
} from "@/serverFunctions/lighthouse";
import { downloadFile } from "@/client/lib/download";
-import { getStandardErrorMessage } from "@/client/lib/error-messages";
+import { QueryError } from "@/client/components/QueryState";
+import { getErrorCode } from "@/client/lib/error-messages";
import { exportTableToSheets } from "@/client/lib/exportToSheets";
import type { CategoryTab, ExportPayload, LighthouseIssue } from "./types";
import { categoryLabel, issuesToCsv, issuesToTable } from "./utils";
@@ -71,10 +72,6 @@ export function LighthouseIssuesScreen(props: LighthouseIssuesScreenProps) {
allIssues: issuesQuery.data?.issues ?? [],
});
- const issuesErrorMessage = getStandardErrorMessage(
- issuesQuery.error,
- "Failed to load Lighthouse issues.",
- );
const showsLegacyPayloadNotice =
issuesQuery.data != null && !issuesQuery.data.hasIssueDetails;
const emptyMessage = showsLegacyPayloadNotice
@@ -87,6 +84,7 @@ export function LighthouseIssuesScreen(props: LighthouseIssuesScreenProps) {
<LighthouseIssuesHeader
backLabel={backLabel}
onBack={onBack}
+ isLoading={issuesQuery.isPending}
scannedAt={issuesQuery.data?.createdAt}
finalUrl={issuesQuery.data?.finalUrl}
scores={issuesQuery.data?.scores}
@@ -97,10 +95,17 @@ export function LighthouseIssuesScreen(props: LighthouseIssuesScreenProps) {
<div className="card bg-base-100 border border-base-300">
<div className="card-body gap-4">
{issuesQuery.isError ? (
- <div className="alert alert-error">
- <AlertCircle className="size-4" />
- <span>{issuesErrorMessage}</span>
- </div>
+ <QueryError
+ error={issuesQuery.error}
+ fallback="Failed to load Lighthouse issues."
+ // A missing result stays missing, so retry cannot help.
+ onRetry={
+ getErrorCode(issuesQuery.error) === "NOT_FOUND"
+ ? undefined
+ : () => void issuesQuery.refetch()
+ }
+ isRetrying={issuesQuery.isFetching}
+ />
) : null}
{showsLegacyPayloadNotice ? (
diff --git a/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx b/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx
index 3ccd8e55..fc186dfa 100644
--- a/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx
+++ b/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx
@@ -2,6 +2,8 @@ import * as React from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { ArrowLeft, ArrowRight, Check } from "lucide-react";
import { GoogleGlyph } from "@/client/features/gsc/GoogleGlyph";
+import { QueryError } from "@/client/components/QueryState";
+import { Spinner } from "@/client/components/Spinner";
import { GoogleLinkErrorAlert } from "@/client/features/integrations/GoogleLinkErrorAlert";
import { SelfHostedSetupWarning } from "@/client/features/gsc/SelfHostedSetupWarning";
import {
@@ -57,7 +59,16 @@ export function SearchConsoleOnboardingStep(props: NavigationProps) {
<GscConnect key={project.id} projectId={project.id} {...props} />
) : (
<>
- <Checking />
+ {projectsQuery.isError ? (
+ <QueryError
+ error={projectsQuery.error}
+ fallback="Couldn't load your project."
+ onRetry={() => void projectsQuery.refetch()}
+ isRetrying={projectsQuery.isFetching}
+ />
+ ) : (
+ <Spinner size="sm" label="Checking…" />
+ )}
<StepNavigation {...props} />
</>
)}
@@ -135,18 +146,13 @@ function GscConnect({
return (
<fieldset disabled={busy}>
{connectionQuery.isLoading ? (
- <Checking />
+ <Spinner size="sm" label="Checking…" />
) : connectionQuery.isError && !connection ? (
- <div role="alert" className="text-sm">
- <p>Couldn't check your Google connection.</p>
- <button
- type="button"
- className="btn btn-ghost btn-sm"
- onClick={() => void connectionQuery.refetch()}
- >
- Try again
- </button>
- </div>
+ <QueryError
+ fallback="Couldn't check your Google connection."
+ onRetry={() => void connectionQuery.refetch()}
+ isRetrying={connectionQuery.isFetching}
+ />
) : needsSetup ? (
<SelfHostedSetupWarning />
) : connected ? (
@@ -256,12 +262,3 @@ function StepNavigation({
</div>
);
}
-
-function Checking() {
- return (
- <div className="flex items-center gap-2 text-sm text-base-content/50">
- <span className="loading loading-spinner loading-sm" />
- Checking…
- </div>
- );
-}
diff --git a/src/client/features/projects/ProjectGeneralSettings.tsx b/src/client/features/projects/ProjectGeneralSettings.tsx
index 85ebec72..f6de96c7 100644
--- a/src/client/features/projects/ProjectGeneralSettings.tsx
+++ b/src/client/features/projects/ProjectGeneralSettings.tsx
@@ -2,6 +2,7 @@ import * as React from "react";
import { useNavigate } from "@tanstack/react-router";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
+import { QueryError, QueryState } from "@/client/components/QueryState";
import { ProjectMarketFields } from "@/client/features/projects/ProjectMarketFields";
import {
clearLastProjectId,
@@ -19,23 +20,26 @@ export function ProjectGeneralSettings({ projectId }: { projectId: string }) {
queryKey: ["projects"],
queryFn: () => getProjects(),
});
- const projects = projectsQuery.data ?? [];
- const project = projects.find((entry) => entry.id === projectId) ?? null;
-
- if (!project) {
- return (
- <div className="flex justify-center py-10">
- <span className="loading loading-spinner loading-md" />
- </div>
- );
- }
return (
- <div className="space-y-8">
- {/* key resets the form's local state when switching between projects */}
- <GeneralSection key={project.id} project={project} />
- <DangerSection project={project} canArchive={projects.length > 1} />
- </div>
+ <QueryState
+ query={projectsQuery}
+ errorFallback="Failed to load the project"
+ >
+ {(projects) => {
+ const project = projects.find((entry) => entry.id === projectId);
+ if (!project) {
+ return <QueryError fallback="This project was not found." />;
+ }
+ return (
+ <div className="space-y-8">
+ {/* key resets the form's local state when switching between projects */}
+ <GeneralSection key={project.id} project={project} />
+ <DangerSection project={project} canArchive={projects.length > 1} />
+ </div>
+ );
+ }}
+ </QueryState>
);
}
diff --git a/src/client/features/projects/project-context/ProjectContextPage.tsx b/src/client/features/projects/project-context/ProjectContextPage.tsx
index 2d8cc28f..9fe311bc 100644
--- a/src/client/features/projects/project-context/ProjectContextPage.tsx
+++ b/src/client/features/projects/project-context/ProjectContextPage.tsx
@@ -1,7 +1,7 @@
import * as React from "react";
import { useQuery } from "@tanstack/react-query";
import { Pencil } from "lucide-react";
-import { getStandardErrorMessage } from "@/client/lib/error-messages";
+import { QueryState } from "@/client/components/QueryState";
import { getProjectContext } from "@/serverFunctions/projectContext";
import {
PROJECT_CONTEXT_SECTION_KEYS,
@@ -51,59 +51,46 @@ export function ProjectContextPage({ projectId }: { projectId: string }) {
staleTime: 0,
});
- if (contextQuery.isPending) {
- return (
- <div className="flex justify-center py-10">
- <span className="loading loading-spinner loading-md" />
- </div>
- );
- }
-
- if (contextQuery.isError) {
- return (
- <div className="alert alert-error">
- <span className="text-sm">
- {getStandardErrorMessage(
- contextQuery.error,
- "Failed to load project context",
- )}
- </span>
- </div>
- );
- }
-
- const context = contextQuery.data;
-
return (
- // key remounts the whole page when the project switches under it, so no
- // draft, open form, or edit state can carry over to another project.
- <div key={projectId} className="space-y-8">
- <p className="text-sm text-base-content/70">
- What SAM, Claude Code, and any connected MCP client know about this
- project. They read it before they work and write back what they learn,
- so correct anything that looks wrong.
- </p>
+ <QueryState
+ query={contextQuery}
+ errorFallback="Failed to load project context"
+ >
+ {(context) => (
+ // key remounts the whole page when the project switches under it, so no
+ // draft, open form, or edit state can carry over to another project.
+ <div key={projectId} className="space-y-8">
+ <p className="text-sm text-base-content/70">
+ What SAM, Claude Code, and any connected MCP client know about this
+ project. They read it before they work and write back what they
+ learn, so correct anything that looks wrong.
+ </p>
- <ProseSections
- projectId={projectId}
- sections={context.sections}
- missingSections={context.missingSections}
- />
+ <ProseSections
+ projectId={projectId}
+ sections={context.sections}
+ missingSections={context.missingSections}
+ />
- <CompetitorsSection
- projectId={projectId}
- competitors={context.competitors}
- />
+ <CompetitorsSection
+ projectId={projectId}
+ competitors={context.competitors}
+ />
- <KeyPagesSection projectId={projectId} keyPages={context.keyPages} />
+ <KeyPagesSection projectId={projectId} keyPages={context.keyPages} />
- <CustomSections
- projectId={projectId}
- customSections={context.customSections}
- />
+ <CustomSections
+ projectId={projectId}
+ customSections={context.customSections}
+ />
- <ResearchLog projectId={projectId} researchLog={context.researchLog} />
- </div>
+ <ResearchLog
+ projectId={projectId}
+ researchLog={context.researchLog}
+ />
+ </div>
+ )}
+ </QueryState>
);
}
diff --git a/src/client/features/rank-tracking/RankTrackingConfigModal.tsx b/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
index d031b1c2..f6ffa3f7 100644
--- a/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
+++ b/src/client/features/rank-tracking/RankTrackingConfigModal.tsx
@@ -1,4 +1,5 @@
import { useMemo, useState } from "react";
+import { useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { Info, Loader2, X } from "lucide-react";
import { Modal } from "@/client/components/Modal";
@@ -16,7 +17,9 @@ import {
} from "@/shared/keyword-locations";
import { LocationSelect } from "@/client/components/LocationSelect";
import type { ProjectMarket } from "@/client/features/projects/types";
-import { useProjectMarket } from "@/client/features/projects/useProjectMarket";
+import { QueryError } from "@/client/components/QueryState";
+import { Spinner } from "@/client/components/Spinner";
+import { getProjects } from "@/serverFunctions/projects";
import { SearchTargetingField } from "./SearchTargetingField";
import { KeywordSuggestionStep } from "./KeywordSuggestionStep";
import { useSaveConfigMutations } from "./useSaveConfigMutations";
@@ -42,9 +45,17 @@ export function RankTrackingConfigModal({
onSaved,
onConfigCreated,
}: Props) {
- const projectMarket = useProjectMarket(projectId);
+ // A new domain starts from the project's market, so it waits for projects.
+ const projectsQuery = useQuery({
+ queryKey: ["projects"],
+ queryFn: () => getProjects(),
+ enabled: !existingConfig,
+ });
+ const initialMarket =
+ existingConfig ??
+ projectsQuery.data?.find((project) => project.id === projectId);
- if (!existingConfig && !projectMarket) {
+ if (!initialMarket) {
return (
<Modal
maxWidth="max-w-lg"
@@ -55,7 +66,16 @@ export function RankTrackingConfigModal({
Add Domain
</h2>
<div className="flex min-h-40 items-center justify-center">
- <Loader2 className="size-5 animate-spin text-base-content/50" />
+ {projectsQuery.isPending ? (
+ <Spinner />
+ ) : (
+ <QueryError
+ error={projectsQuery.error}
+ fallback="Failed to load the project."
+ onRetry={() => void projectsQuery.refetch()}
+ isRetrying={projectsQuery.isFetching}
+ />
+ )}
</div>
</Modal>
);
@@ -65,7 +85,7 @@ export function RankTrackingConfigModal({
<RankTrackingConfigModalContent
projectId={projectId}
existingConfig={existingConfig}
- initialMarket={existingConfig ?? projectMarket!}
+ initialMarket={initialMarket}
onClose={onClose}
onSaved={onSaved}
onConfigCreated={onConfigCreated}
diff --git a/src/client/features/rank-tracking/RankTrackingDomainList.tsx b/src/client/features/rank-tracking/RankTrackingDomainList.tsx
index c8f84e0c..66d24369 100644
--- a/src/client/features/rank-tracking/RankTrackingDomainList.tsx
+++ b/src/client/features/rank-tracking/RankTrackingDomainList.tsx
@@ -27,6 +27,7 @@ import {
getDomainListFilterOptions,
type DomainListFilters,
} from "./RankTrackingFilters";
+import { Skeleton } from "@/client/components/Skeleton";
type ConfigSummary = Awaited<
ReturnType<typeof getRankTrackingConfigSummaries>
@@ -111,8 +112,8 @@ export function RankTrackingDomainList({
<div className="space-y-4 px-5 py-4" aria-busy>
{Array.from({ length: 3 }).map((_, index) => (
<div key={index} className="space-y-2">
- <div className="skeleton h-4 w-48" />
- <div className="skeleton h-3 w-72" />
+ <Skeleton className="h-4 w-48" />
+ <Skeleton className="h-3 w-72" />
</div>
))}
</div>
diff --git a/src/client/features/sam/SamChat.tsx b/src/client/features/sam/SamChat.tsx
index f9b05ceb..8d264e4a 100644
--- a/src/client/features/sam/SamChat.tsx
+++ b/src/client/features/sam/SamChat.tsx
@@ -1,7 +1,9 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { Link, useNavigate } from "@tanstack/react-router";
-import { Suspense, useCallback, useEffect, useRef } from "react";
-import { Brain, Loader2 } from "lucide-react";
+import { Suspense, useCallback, useEffect, useRef, useState } from "react";
+import { Brain } from "lucide-react";
+import { QueryError } from "@/client/components/QueryState";
+import { Spinner } from "@/client/components/Spinner";
import { createSamSession } from "@/serverFunctions/sam";
import {
invalidateSamSessions,
@@ -47,8 +49,14 @@ export function SamChat({
// effect before the mutation state updates, and it resets on settle so
// archiving the last chat starts a fresh one.
const creating = useRef(false);
+ // Kept in state: the mutation's own callbacks fire for the create started
+ // from the effect below, but the hook's `isError` can miss it and leave the
+ // spinner up.
+ const [createError, setCreateError] = useState<Error | null>(null);
const createSession = useMutation({
mutationFn: () => createSamSession({ data: { projectId } }),
+ onMutate: () => setCreateError(null),
+ onError: (error) => setCreateError(error),
onSuccess: ({ id }) => {
invalidateSamSessions(projectId);
goToSession(id);
@@ -105,10 +113,29 @@ export function SamChat({
if (!activeSessionId) {
// Sessions are loading or a fresh chat is being created; the effect above
- // redirects into it.
+ // redirects into it. Either request can fail, and neither retries itself.
+ const loadFailed = sessionsQuery.isError && !sessionsQuery.data;
return (
- <div className="flex h-full items-center justify-center">
- <Loader2 className="size-5 animate-spin text-base-content/40" />
+ <div className="flex h-full items-center justify-center p-4">
+ {loadFailed ? (
+ <QueryError
+ error={sessionsQuery.error}
+ fallback="Failed to load your chats."
+ onRetry={() => void sessionsQuery.refetch()}
+ isRetrying={sessionsQuery.isFetching}
+ />
+ ) : createError ? (
+ <QueryError
+ error={createError}
+ fallback="Failed to start a new chat."
+ onRetry={() => {
+ creating.current = true;
+ createSessionMutate();
+ }}
+ />
+ ) : (
+ <Spinner />
+ )}
</div>
);
}
@@ -141,7 +168,7 @@ export function SamChat({
<Suspense
fallback={
<div className="flex flex-1 items-center justify-center">
- <Loader2 className="size-5 animate-spin text-base-content/40" />
+ <Spinner />
</div>
}
>
diff --git a/src/client/features/saved-keywords/SavedKeywordsTable.tsx b/src/client/features/saved-keywords/SavedKeywordsTable.tsx
index bfe4fcb9..4146390e 100644
--- a/src/client/features/saved-keywords/SavedKeywordsTable.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsTable.tsx
@@ -22,6 +22,7 @@ import {
formatSavedKeywordDate,
formatSavedKeywordNumber,
} from "./savedKeywordsUtils";
+import { Skeleton } from "@/client/components/Skeleton";
const columnHelper = createColumnHelper<SavedKeywordRow>();
@@ -168,17 +169,17 @@ function TagList({ tags }: { tags: SavedKeywordRow["tags"] }) {
function SavedKeywordsSkeleton() {
return (
<div className="space-y-3" aria-busy>
- <div className="skeleton h-4 w-48" />
+ <Skeleton className="h-4 w-48" />
{Array.from({ length: 8 }).map((_, index) => (
<div key={index} className="grid grid-cols-9 items-center gap-3">
- <div className="skeleton h-4" />
- <div className="skeleton col-span-2 h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="col-span-2 h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
</div>
))}
</div>
diff --git a/src/client/features/search-performance/SearchPerformanceLoadingState.tsx b/src/client/features/search-performance/SearchPerformanceLoadingState.tsx
index df42e757..35424e55 100644
--- a/src/client/features/search-performance/SearchPerformanceLoadingState.tsx
+++ b/src/client/features/search-performance/SearchPerformanceLoadingState.tsx
@@ -1,3 +1,5 @@
+import { Skeleton } from "@/client/components/Skeleton";
+
// Skeleton loading state for the Search Performance (GSC) page. Mirrors the
// loaded layout — four totals cards over a tabbed table panel — so the shell
// stays put and only the data fills in, matching the other pages' loaders
@@ -11,8 +13,8 @@ export function SearchPerformanceLoadingState() {
key={index}
className="rounded-lg border border-base-300 bg-base-100 p-4 space-y-2"
>
- <div className="skeleton h-3 w-20" />
- <div className="skeleton h-7 w-24" />
+ <Skeleton className="h-3 w-20" />
+ <Skeleton className="h-7 w-24" />
</div>
))}
</div>
@@ -20,24 +22,24 @@ export function SearchPerformanceLoadingState() {
<div className="overflow-hidden rounded-xl border border-base-300 bg-base-100">
<div className="flex flex-col gap-3 border-b border-base-300 px-4 py-3 lg:flex-row lg:items-center lg:justify-between">
<div className="flex items-center gap-4">
- <div className="skeleton h-8 w-40" />
- <div className="skeleton h-8 w-20" />
- <div className="skeleton h-8 w-16" />
+ <Skeleton className="h-8 w-40" />
+ <Skeleton className="h-8 w-20" />
+ <Skeleton className="h-8 w-16" />
</div>
<div className="flex flex-wrap items-center gap-2">
- <div className="skeleton h-8 w-36" />
- <div className="skeleton h-8 w-36" />
- <div className="skeleton h-8 w-36" />
+ <Skeleton className="h-8 w-36" />
+ <Skeleton className="h-8 w-36" />
+ <Skeleton className="h-8 w-36" />
</div>
</div>
<div className="space-y-3 p-4">
{Array.from({ length: 8 }).map((_, index) => (
<div key={index} className="grid grid-cols-5 gap-3">
- <div className="skeleton col-span-2 h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
- <div className="skeleton h-4" />
+ <Skeleton className="col-span-2 h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
+ <Skeleton className="h-4" />
</div>
))}
</div>
diff --git a/src/client/features/settings/ApiKeySettings.tsx b/src/client/features/settings/ApiKeySettings.tsx
index 87ceeccd..34e11146 100644
--- a/src/client/features/settings/ApiKeySettings.tsx
+++ b/src/client/features/settings/ApiKeySettings.tsx
@@ -1,4 +1,5 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { QueryState } from "@/client/components/QueryState";
import { Trash2 } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
@@ -68,8 +69,6 @@ export function ApiKeySettings() {
},
});
- const apiKeys = apiKeysQuery.data ?? [];
-
const closeCreateModal = () => {
setIsCreateOpen(false);
setCreatedKey(null);
@@ -108,76 +107,83 @@ export function ApiKeySettings() {
</button>
</div>
- {apiKeysQuery.isError ? (
- <p className="text-sm text-error">We couldn't load your API keys.</p>
- ) : apiKeys.length > 0 ? (
- <div className="overflow-x-auto rounded-lg border border-base-300">
- <table className="table table-sm">
- <thead>
- <tr>
- <th>Name</th>
- <th>Key</th>
- <th>Created</th>
- <th>Last used</th>
- <th className="w-10"></th>
- </tr>
- </thead>
- <tbody>
- {apiKeys.map((key) => (
- <tr key={key.id} className="hover">
- <td className="max-w-[220px] truncate font-medium">
- {key.name || "Unnamed key"}
- </td>
- <td
- className="font-mono text-xs text-base-content/70"
- data-ph-mask
- >
- {key.start || "oseo_"}…
- </td>
- <td className="text-xs text-base-content/70">
- {key.createdAt.toLocaleDateString()}
- </td>
- <td className="text-xs text-base-content/70">
- {key.lastRequest
- ? key.lastRequest.toLocaleDateString()
- : "Never"}
- </td>
- <td>
- <PortalMenu
- ariaLabel={`Actions for ${key.name || "API key"}`}
- >
- {(close) => (
- <li>
- <button
- className="text-error"
- disabled={
- revokeMutation.isPending &&
- revokeMutation.variables === key.id
- }
- onClick={() => {
- close();
- if (
- window.confirm(
- `Revoke "${key.name || "Unnamed key"}"? Clients using it will stop working.`,
- )
- ) {
- revokeMutation.mutate(key.id);
- }
- }}
- >
- <Trash2 className="size-3.5" />
- Revoke key
- </button>
- </li>
- )}
- </PortalMenu>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- ) : null}
+ <QueryState
+ query={apiKeysQuery}
+ errorFallback="We couldn't load your API keys."
+ >
+ {(apiKeys) =>
+ apiKeys.length === 0 ? (
+ <p className="text-sm text-base-content/60">No API keys yet.</p>
+ ) : (
+ <div className="overflow-x-auto rounded-lg border border-base-300">
+ <table className="table table-sm">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Key</th>
+ <th>Created</th>
+ <th>Last used</th>
+ <th className="w-10"></th>
+ </tr>
+ </thead>
+ <tbody>
+ {apiKeys.map((key) => (
+ <tr key={key.id} className="hover">
+ <td className="max-w-[220px] truncate font-medium">
+ {key.name || "Unnamed key"}
+ </td>
+ <td
+ className="font-mono text-xs text-base-content/70"
+ data-ph-mask
+ >
+ {key.start || "oseo_"}…
+ </td>
+ <td className="text-xs text-base-content/70">
+ {key.createdAt.toLocaleDateString()}
+ </td>
+ <td className="text-xs text-base-content/70">
+ {key.lastRequest
+ ? key.lastRequest.toLocaleDateString()
+ : "Never"}
+ </td>
+ <td>
+ <PortalMenu
+ ariaLabel={`Actions for ${key.name || "API key"}`}
+ >
+ {(close) => (
+ <li>
+ <button
+ className="text-error"
+ disabled={
+ revokeMutation.isPending &&
+ revokeMutation.variables === key.id
+ }
+ onClick={() => {
+ close();
+ if (
+ window.confirm(
+ `Revoke "${key.name || "Unnamed key"}"? Clients using it will stop working.`,
+ )
+ ) {
+ revokeMutation.mutate(key.id);
+ }
+ }}
+ >
+ <Trash2 className="size-3.5" />
+ Revoke key
+ </button>
+ </li>
+ )}
+ </PortalMenu>
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ )
+ }
+ </QueryState>
{isCreateOpen ? (
<div className="modal modal-open">
diff --git a/src/client/features/team/TeamSettings.tsx b/src/client/features/team/TeamSettings.tsx
index 116811d8..a8ca6c0c 100644
--- a/src/client/features/team/TeamSettings.tsx
+++ b/src/client/features/team/TeamSettings.tsx
@@ -1,6 +1,8 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
import { toast } from "sonner";
+import { QueryError } from "@/client/components/QueryState";
+import { PageLoading } from "@/client/components/Spinner";
import {
InviteTeammateModal,
inviteErrorMessage,
@@ -94,20 +96,19 @@ export function TeamSettings() {
const members = teamQuery.data?.members ?? [];
const pendingInvitations = teamQuery.data?.pendingInvitations ?? [];
- if (teamQuery.isError) {
+ // The team query waits on the org context, so a failed context would
+ // otherwise leave the team spinner up for good.
+ const failedQuery = [orgContextQuery, teamQuery].find(
+ (query) => query.isError && query.data === undefined,
+ );
+ if (failedQuery) {
return (
- <div className="space-y-3">
- <p className="text-sm text-base-content/70">
- We couldn&rsquo;t load your team right now.
- </p>
- <button
- type="button"
- className="btn btn-soft btn-sm"
- onClick={() => void teamQuery.refetch()}
- >
- Try again
- </button>
- </div>
+ <QueryError
+ error={failedQuery.error}
+ fallback="We couldn't load your team right now."
+ onRetry={() => void failedQuery.refetch()}
+ isRetrying={failedQuery.isFetching}
+ />
);
}
@@ -131,9 +132,7 @@ export function TeamSettings() {
</p>
{teamQuery.isPending ? (
- <div className="flex justify-center py-6">
- <span className="loading loading-spinner loading-md" />
- </div>
+ <PageLoading />
) : (
<div className="overflow-x-auto rounded-lg border border-base-300">
<table className="table table-sm">
diff --git a/src/routes/_app/billing.tsx b/src/routes/_app/billing.tsx
index e988c6b9..08c0ce25 100644
--- a/src/routes/_app/billing.tsx
+++ b/src/routes/_app/billing.tsx
@@ -1,6 +1,8 @@
import { createFileRoute, notFound } from "@tanstack/react-router";
import { useCustomer } from "autumn-js/react";
import { useState } from "react";
+import { QueryError } from "@/client/components/QueryState";
+import { PageLoading } from "@/client/components/Spinner";
import { useSession } from "@/lib/auth-client";
import { isHostedClientAuthMode } from "@/lib/auth-mode";
import { useCanManageBilling } from "@/client/features/team/organizationQueries";
@@ -81,28 +83,19 @@ function BillingPage() {
parseTopUpAmount(topUpAmount);
if (billingRouteState === "loading") {
- return null;
+ return <PageLoading />;
}
if (billingRouteState === "error") {
return (
<div className="mx-auto w-full max-w-2xl space-y-4 p-4 py-10 md:p-6 md:py-12">
<h1 className="text-xl font-semibold">Billing unavailable</h1>
- <p className="text-sm text-base-content/70">
- {getStandardErrorMessage(
- customerQuery.error,
- "We couldn't load your billing details right now. Please try again.",
- )}
- </p>
- <button
- type="button"
- className="btn btn-soft btn-sm"
- onClick={() => {
- void customerQuery.refetch();
- }}
- >
- Try again
- </button>
+ <QueryError
+ error={customerQuery.error}
+ fallback="We couldn't load your billing details right now. Please try again."
+ onRetry={() => void customerQuery.refetch()}
+ isRetrying={customerQuery.isFetching}
+ />
</div>
);
}
diff --git a/src/routes/_app/index.tsx b/src/routes/_app/index.tsx
index c26beeaa..e19a2045 100644
--- a/src/routes/_app/index.tsx
+++ b/src/routes/_app/index.tsx
@@ -11,6 +11,8 @@ import {
getStandardErrorMessage,
} from "@/client/lib/error-messages";
import { AuthConfigErrorCard } from "@/client/components/AuthConfigErrorCard";
+import { QueryError } from "@/client/components/QueryState";
+import { Spinner } from "@/client/components/Spinner";
import { UnauthenticatedErrorCard } from "@/client/components/UnauthenticatedErrorCard";
import { SUBSCRIBE_ROUTE } from "@/shared/billing";
@@ -21,7 +23,7 @@ export const Route = createFileRoute("/_app/")({
function IndexRedirect() {
const navigate = useNavigate();
- const { data, error, isError, refetch } = useQuery({
+ const { data, error, isError, isFetching, refetch } = useQuery({
queryKey: ["projects"],
queryFn: () => getProjects(),
retry: false,
@@ -99,13 +101,13 @@ function IndexRedirect() {
return (
<div className="flex items-center justify-center h-full p-4">
- <div className="flex flex-col items-center gap-3 max-w-xl">
- <p className="text-error text-center">
- {getStandardErrorMessage(
- error,
- "An unexpected error occurred. Please check server logs.",
- )}
- </p>
+ <div className="w-full max-w-xl">
+ <QueryError
+ error={error}
+ fallback="An unexpected error occurred. Please check server logs."
+ onRetry={() => void refetch()}
+ isRetrying={isFetching}
+ />
</div>
</div>
);
@@ -113,7 +115,7 @@ function IndexRedirect() {
return (
<div className="flex items-center justify-center h-full">
- <span className="loading loading-spinner loading-md" />
+ <Spinner />
</div>
);
}
diff --git a/src/routes/_app/projects.tsx b/src/routes/_app/projects.tsx
index 8a593a6e..23a77962 100644
--- a/src/routes/_app/projects.tsx
+++ b/src/routes/_app/projects.tsx
@@ -8,6 +8,7 @@ import {
getProjects,
restoreProject,
} from "@/serverFunctions/projects";
+import { QueryState } from "@/client/components/QueryState";
import { getLastProjectId } from "@/client/lib/active-project";
import { CreateProjectModal } from "@/client/features/projects/CreateProjectModal";
@@ -28,7 +29,6 @@ function ProjectsPage() {
queryKey: ["projects"],
queryFn: () => getProjects(),
});
- const projects = projectsQuery.data ?? [];
return (
<div className="h-full overflow-auto bg-base-100 px-4 py-8 pb-24 md:px-6 md:py-12 md:pb-8">
@@ -51,40 +51,41 @@ function ProjectsPage() {
</button>
</div>
- {projectsQuery.isLoading ? (
- <div className="flex justify-center py-10">
- <span className="loading loading-spinner loading-md" />
- </div>
- ) : (
- <ul className="divide-y divide-base-300 overflow-hidden rounded-lg border border-base-300">
- {projects.map((project) => (
- <li key={project.id}>
- <Link
- to="/p/$projectId/settings"
- params={{ projectId: project.id }}
- className="flex items-center justify-between gap-3 p-3 transition-colors hover:bg-base-200/40"
- >
- <span className="flex min-w-0 flex-col">
- <span className="flex items-center gap-2">
- <span className="truncate font-medium">
- {project.name}
- </span>
- {project.id === currentProjectId ? (
- <span className="shrink-0 rounded-full bg-base-300/70 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-base-content/60">
- Current
+ <QueryState
+ query={projectsQuery}
+ errorFallback="Failed to load projects"
+ >
+ {(data) => (
+ <ul className="divide-y divide-base-300 overflow-hidden rounded-lg border border-base-300">
+ {data.map((project) => (
+ <li key={project.id}>
+ <Link
+ to="/p/$projectId/settings"
+ params={{ projectId: project.id }}
+ className="flex items-center justify-between gap-3 p-3 transition-colors hover:bg-base-200/40"
+ >
+ <span className="flex min-w-0 flex-col">
+ <span className="flex items-center gap-2">
+ <span className="truncate font-medium">
+ {project.name}
</span>
- ) : null}
- </span>
- <span className="truncate text-xs text-base-content/50">
- {project.domain ?? "No domain set"}
+ {project.id === currentProjectId ? (
+ <span className="shrink-0 rounded-full bg-base-300/70 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-base-content/60">
+ Current
+ </span>
+ ) : null}
+ </span>
+ <span className="truncate text-xs text-base-content/50">
+ {project.domain ?? "No domain set"}
+ </span>
</span>
- </span>
- <ChevronRight className="size-4 shrink-0 text-base-content/40" />
- </Link>
- </li>
- ))}
- </ul>
- )}
+ <ChevronRight className="size-4 shrink-0 text-base-content/40" />
+ </Link>
+ </li>
+ ))}
+ </ul>
+ )}
+ </QueryState>
<ArchivedProjects />
</div>
diff --git a/src/routes/_app/route.tsx b/src/routes/_app/route.tsx
index 15582ab8..98c11d66 100644
--- a/src/routes/_app/route.tsx
+++ b/src/routes/_app/route.tsx
@@ -1,5 +1,6 @@
import { Outlet, createFileRoute } from "@tanstack/react-router";
import { useHostedAuthRouteGuard } from "@/client/features/auth/useHostedAuthRouteGuard";
+import { PageLoading } from "@/client/components/Spinner";
import { AuthenticatedAppLayout } from "@/client/layout/AppShell";
import { useOnboardingRedirect } from "@/client/features/onboarding/useOnboardingRedirect";
@@ -12,7 +13,7 @@ function AppRouteLayout() {
useOnboardingRedirect();
if (!authGate.canRenderAuthenticatedContent) {
- return null;
+ return <PageLoading fullScreen />;
}
return (
diff --git a/src/routes/_auth.tsx b/src/routes/_auth.tsx
index 681c9a18..4d84796a 100644
--- a/src/routes/_auth.tsx
+++ b/src/routes/_auth.tsx
@@ -5,6 +5,7 @@ import {
authRedirectSearchSchema,
} from "@/client/features/auth/AuthPage";
import { useSession } from "@/lib/auth-client";
+import { PageLoading } from "@/client/components/Spinner";
import { isHostedClientAuthMode } from "@/lib/auth-mode";
import { getCurrentAuthRedirect, isDocumentRoute } from "@/lib/auth-redirect";
@@ -38,8 +39,9 @@ function AuthPageLayout() {
});
}, [navigate, redirectTo, session?.user?.id]);
+ // Loading the session, or handing a signed-in user off to the destination.
if (isHostedMode && (isPending || session?.user?.id)) {
- return null;
+ return <PageLoading fullScreen />;
}
return (
diff --git a/src/routes/_authenticated.subscribe.tsx b/src/routes/_authenticated.subscribe.tsx
index c645fa3a..4b8ab0f2 100644
--- a/src/routes/_authenticated.subscribe.tsx
+++ b/src/routes/_authenticated.subscribe.tsx
@@ -2,6 +2,8 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useCustomer } from "autumn-js/react";
import { useEffect, useState } from "react";
import { ArrowRight } from "lucide-react";
+import { QueryError } from "@/client/components/QueryState";
+import { Spinner } from "@/client/components/Spinner";
import { PlanPageAccountMenu } from "@/client/features/billing/PlanPageAccountMenu";
import { PlanOfferCard } from "@/client/features/billing/PlanOfferCard";
import {
@@ -129,7 +131,7 @@ function SubscribePage() {
subscribeRouteState === "loading" ||
subscribeRouteState === "redirectToApp"
) {
- return null;
+ return <Spinner />;
}
if (subscribeRouteState === "finalizing") {
@@ -143,7 +145,7 @@ function SubscribePage() {
<h1 className="text-xl font-semibold">
Finalizing your subscription&hellip;
</h1>
- <span className="loading loading-spinner loading-md" />
+ <Spinner />
<p className="text-sm text-base-content/60">
This usually takes a few seconds.
</p>
@@ -170,22 +172,12 @@ function SubscribePage() {
<h1 className="text-xl font-semibold">Billing unavailable</h1>
</div>
- <p className="text-sm text-center text-base-content/70">
- {getStandardErrorMessage(
- customerQuery.error,
- "We couldn't verify your billing status right now. Please try again.",
- )}
- </p>
-
- <button
- type="button"
- className="btn btn-soft w-full"
- onClick={() => {
- void customerQuery.refetch();
- }}
- >
- Try again
- </button>
+ <QueryError
+ error={customerQuery.error}
+ fallback="We couldn't verify your billing status right now. Please try again."
+ onRetry={() => void customerQuery.refetch()}
+ isRetrying={customerQuery.isFetching}
+ />
</div>
);
}
diff --git a/src/routes/_authenticated.tsx b/src/routes/_authenticated.tsx
index 32b8bb13..bba0f914 100644
--- a/src/routes/_authenticated.tsx
+++ b/src/routes/_authenticated.tsx
@@ -1,6 +1,7 @@
import { Outlet, createFileRoute } from "@tanstack/react-router";
import { AuthPageShell } from "@/client/features/auth/AuthPage";
import { useHostedAuthRouteGuard } from "@/client/features/auth/useHostedAuthRouteGuard";
+import { PageLoading } from "@/client/components/Spinner";
export const Route = createFileRoute("/_authenticated")({
component: AuthenticatedShellLayout,
@@ -9,10 +10,15 @@ export const Route = createFileRoute("/_authenticated")({
function AuthenticatedShellLayout() {
const authGate = useHostedAuthRouteGuard();
- if (!authGate.isHostedMode || !authGate.canRenderAuthenticatedContent) {
+ // Every page under this layout is hosted-only.
+ if (!authGate.isHostedMode) {
return null;
}
+ if (!authGate.canRenderAuthenticatedContent) {
+ return <PageLoading fullScreen />;
+ }
+
return (
<AuthPageShell>
<Outlet />
diff --git a/src/routes/_project/p/$projectId/audit/index.tsx b/src/routes/_project/p/$projectId/audit/index.tsx
index 17df9349..7f8bb3f4 100644
--- a/src/routes/_project/p/$projectId/audit/index.tsx
+++ b/src/routes/_project/p/$projectId/audit/index.tsx
@@ -7,6 +7,8 @@ import {
getAuditStatus,
getCrawlProgress,
} from "@/serverFunctions/audit";
+import { QueryError, QueryState } from "@/client/components/QueryState";
+import { PageLoading } from "@/client/components/Spinner";
import { auditSearchSchema } from "@/types/schemas/audit";
import { LaunchView } from "@/client/features/audit/launch/LaunchView";
import { ResultsView } from "@/client/features/audit/results/ResultsView";
@@ -97,21 +99,18 @@ function AuditDetail({
});
if (statusQuery.isLoading) {
- return (
- <div className="flex items-center justify-center py-20">
- <span className="loading loading-spinner loading-lg" />
- </div>
- );
+ return <PageLoading />;
}
if (statusQuery.isError) {
return (
<div className="px-4 py-6 md:px-6">
<div className="mx-auto max-w-3xl space-y-4">
- <div className="alert alert-error">
- <AlertCircle className="size-5" />
- <span>We could not load this audit. It may have been deleted.</span>
- </div>
+ <QueryError
+ fallback="We could not load this audit. It may have been deleted."
+ onRetry={() => void statusQuery.refetch()}
+ isRetrying={statusQuery.isFetching}
+ />
<button className="btn btn-ghost btn-sm" onClick={onBack}>
&larr; Back to audits
</button>
@@ -220,13 +219,22 @@ function AuditDetail({
</div>
)}
- {(isComplete || failedWithResults) && resultsQuery.data && (
- <ResultsView
- projectId={projectId}
- data={resultsQuery.data}
- tab={tab}
- onTabChange={onTabChange}
- />
+ {(isComplete || isFailed) && (
+ <QueryState
+ query={resultsQuery}
+ errorFallback="Failed to load the audit results"
+ >
+ {(data) =>
+ (isComplete || failedWithResults) && (
+ <ResultsView
+ projectId={projectId}
+ data={data}
+ tab={tab}
+ onTabChange={onTabChange}
+ />
+ )
+ }
+ </QueryState>
)}
</div>
</div>
diff --git a/src/routes/_project/p/$projectId/rank-tracking/$configId.tsx b/src/routes/_project/p/$projectId/rank-tracking/$configId.tsx
index 742fcd06..76a4d636 100644
--- a/src/routes/_project/p/$projectId/rank-tracking/$configId.tsx
+++ b/src/routes/_project/p/$projectId/rank-tracking/$configId.tsx
@@ -3,6 +3,7 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { getRankTrackingConfigs } from "@/serverFunctions/rank-tracking";
import { RankTrackingDomainDetail } from "@/client/features/rank-tracking/RankTrackingDomainDetail";
+import { PageLoading } from "@/client/components/Spinner";
import { RankTrackingConfigModal } from "@/client/features/rank-tracking/RankTrackingConfigModal";
export const Route = createFileRoute(
@@ -41,11 +42,7 @@ function RankTrackingConfigRoute() {
};
if (isPending) {
- return (
- <div className="flex items-center justify-center py-20">
- <span className="loading loading-spinner loading-lg" />
- </div>
- );
+ return <PageLoading />;
}
if (!config) {
diff --git a/src/routes/_project/p/$projectId/reports/$reportId.tsx b/src/routes/_project/p/$projectId/reports/$reportId.tsx
index 51fb0212..01169597 100644
--- a/src/routes/_project/p/$projectId/reports/$reportId.tsx
+++ b/src/routes/_project/p/$projectId/reports/$reportId.tsx
@@ -14,6 +14,8 @@ import {
} from "lucide-react";
import { z } from "zod";
import { PortalMenu } from "@/client/components/PortalMenu";
+import { QueryError } from "@/client/components/QueryState";
+import { PageLoading } from "@/client/components/Spinner";
import { ReportViewer } from "@/client/features/reports/ReportViewer";
import {
DeleteReportModal,
@@ -24,10 +26,7 @@ import {
} from "@/client/features/reports/shared";
import { formatRelativeTime } from "@/client/lib/relative-time";
import { isHostedClientAuthMode } from "@/lib/auth-mode";
-import {
- getErrorCode,
- getStandardErrorMessage,
-} from "@/client/lib/error-messages";
+import { getErrorCode } from "@/client/lib/error-messages";
import { captureClientEvent } from "@/client/lib/posthog";
import { getReport } from "@/serverFunctions/reports";
@@ -115,29 +114,27 @@ function ReportDetailPage() {
}, [full, setExpanded]);
if (reportQuery.isPending) {
- return (
- <div className="flex justify-center py-10">
- <span className="loading loading-spinner loading-md" />
- </div>
- );
+ return <PageLoading />;
}
if (reportQuery.isError || !report) {
+ const notFound = getErrorCode(reportQuery.error) === "NOT_FOUND";
return (
<div className="px-4 py-6 md:px-6">
<div className="mx-auto max-w-3xl space-y-4">
- <div className="alert alert-error">
- <span className="text-sm">
- {/* A deleted report and another project's report are the
- same answer on purpose, so ids cannot be probed. */}
- {getErrorCode(reportQuery.error) === "NOT_FOUND"
- ? "This report does not exist or you do not have access to it."
- : getStandardErrorMessage(
- reportQuery.error,
- "Failed to load the report",
- )}
- </span>
- </div>
+ {/* A deleted report and another project's report are the same
+ answer on purpose, so ids cannot be probed. Retrying either
+ cannot help. */}
+ {notFound ? (
+ <QueryError fallback="This report does not exist or you do not have access to it." />
+ ) : (
+ <QueryError
+ error={reportQuery.error}
+ fallback="Failed to load the report"
+ onRetry={() => void reportQuery.refetch()}
+ isRetrying={reportQuery.isFetching}
+ />
+ )}
<Link
to="/p/$projectId/reports"
params={{ projectId }}
diff --git a/src/routes/_project/p/$projectId/reports/index.tsx b/src/routes/_project/p/$projectId/reports/index.tsx
index 269bbc0a..5c0ff689 100644
--- a/src/routes/_project/p/$projectId/reports/index.tsx
+++ b/src/routes/_project/p/$projectId/reports/index.tsx
@@ -7,7 +7,7 @@ import {
reportsQueryKey,
useDeleteReport,
} from "@/client/features/reports/shared";
-import { getStandardErrorMessage } from "@/client/lib/error-messages";
+import { QueryState } from "@/client/components/QueryState";
import { listReports, type ReportListItem } from "@/serverFunctions/reports";
import { REPORT_APP_LIST_LIMIT } from "@/types/schemas/reports";
@@ -53,26 +53,15 @@ function ReportsPage() {
</Link>
</div>
- {reportsQuery.isPending ? (
- <div className="flex justify-center py-10">
- <span className="loading loading-spinner loading-md" />
- </div>
- ) : reportsQuery.isError ? (
- <div className="alert alert-error">
- <span className="text-sm">
- {getStandardErrorMessage(
- reportsQuery.error,
- "Failed to load reports",
- )}
- </span>
- </div>
- ) : (
- <ReportsList
- projectId={projectId}
- reports={reportsQuery.data.reports}
- onDelete={setPendingDelete}
- />
- )}
+ <QueryState query={reportsQuery} errorFallback="Failed to load reports">
+ {(data) => (
+ <ReportsList
+ projectId={projectId}
+ reports={data.reports}
+ onDelete={setPendingDelete}
+ />
+ )}
+ </QueryState>
</div>
{pendingDelete ? (
diff --git a/src/routes/_project/p/$projectId/reports/templates.tsx b/src/routes/_project/p/$projectId/reports/templates.tsx
index 5279f521..e5884821 100644
--- a/src/routes/_project/p/$projectId/reports/templates.tsx
+++ b/src/routes/_project/p/$projectId/reports/templates.tsx
@@ -4,10 +4,10 @@ import { useState } from "react";
import { ChevronLeft, Plus } from "lucide-react";
import { toast } from "sonner";
import { ConfirmDeleteModal } from "@/client/components/ConfirmDeleteModal";
+import { QueryState } from "@/client/components/QueryState";
import { ReportTemplateForm } from "@/client/features/reports/ReportTemplateForm";
import { ReportTemplatesList } from "@/client/features/reports/ReportTemplatesList";
import { reportsQueryKey } from "@/client/features/reports/shared";
-import { getStandardErrorMessage } from "@/client/lib/error-messages";
import { captureClientEvent } from "@/client/lib/posthog";
import {
deleteReportTemplate,
@@ -92,26 +92,18 @@ function ReportTemplatesPage() {
</button>
</div>
- {templatesQuery.isPending ? (
- <div className="flex justify-center py-10">
- <span className="loading loading-spinner loading-md" />
- </div>
- ) : templatesQuery.isError ? (
- <div className="alert alert-error">
- <span className="text-sm">
- {getStandardErrorMessage(
- templatesQuery.error,
- "Failed to load templates",
- )}
- </span>
- </div>
- ) : (
- <ReportTemplatesList
- templates={templatesQuery.data.templates}
- onEdit={(template) => setForm({ template })}
- onDelete={setPendingDelete}
- />
- )}
+ <QueryState
+ query={templatesQuery}
+ errorFallback="Failed to load templates"
+ >
+ {(data) => (
+ <ReportTemplatesList
+ templates={data.templates}
+ onEdit={(template) => setForm({ template })}
+ onDelete={setPendingDelete}
+ />
+ )}
+ </QueryState>
</div>
{form ? (
diff --git a/src/routes/_project/p/$projectId/route.tsx b/src/routes/_project/p/$projectId/route.tsx
index ffb665cc..6cdccf38 100644
--- a/src/routes/_project/p/$projectId/route.tsx
+++ b/src/routes/_project/p/$projectId/route.tsx
@@ -7,6 +7,7 @@ import {
import { useQuery } from "@tanstack/react-query";
import { useEffect } from "react";
import { setLastProjectId } from "@/client/lib/active-project";
+import { PageLoading } from "@/client/components/Spinner";
import { useHostedAuthRouteGuard } from "@/client/features/auth/useHostedAuthRouteGuard";
import { FreePlanBanner } from "@/client/features/billing/FreePlanBanner";
import { useOnboardingRedirect } from "@/client/features/onboarding/useOnboardingRedirect";
@@ -81,7 +82,7 @@ function ProjectLayout() {
}, [projectId, isSettingsPage]);
if (!authGate.canRenderAuthenticatedContent) {
- return null;
+ return <PageLoading fullScreen />;
}
return (
diff --git a/src/routes/accept-invitation.$id.tsx b/src/routes/accept-invitation.$id.tsx
index c4975ab8..7e982487 100644
--- a/src/routes/accept-invitation.$id.tsx
+++ b/src/routes/accept-invitation.$id.tsx
@@ -1,4 +1,5 @@
import { useQuery } from "@tanstack/react-query";
+import { Spinner } from "@/client/components/Spinner";
import { Link, createFileRoute, notFound } from "@tanstack/react-router";
import { useState } from "react";
import { AuthPageCard, AuthPageShell } from "@/client/features/auth/AuthPage";
@@ -21,7 +22,9 @@ function AcceptInvitationPage() {
return (
<AuthPageShell>
- {isSessionPending ? null : session?.user ? (
+ {isSessionPending ? (
+ <Spinner />
+ ) : session?.user ? (
<InvitationCard invitationId={id} userEmail={session.user.email} />
) : (
<SignedOutInvitationCard invitationId={id} />
@@ -144,7 +147,7 @@ function InvitationCard({
return (
<AuthPageCard title="Checking invitation...">
<div className="flex justify-center py-4">
- <span className="loading loading-spinner loading-md" />
+ <Spinner />
</div>
</AuthPageCard>
);