Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Fix conversion follow-ups from the ShadCN-prep stack review (#722)
Ben Senescu6a9713e5cbde
diff --git a/src/client/components/QueryState.tsx b/src/client/components/QueryState.tsxindex cee15c30..bdf6d608 100644--- a/src/client/components/QueryState.tsx+++ b/src/client/components/QueryState.tsx@@ -1,17 +1,29 @@import type { ReactNode } from "react";+import { Link } from "@tanstack/react-router";import type { UseQueryResult } from "@tanstack/react-query";-import { getStandardErrorMessage } from "@/client/lib/error-messages";+import {+ getErrorCode,+ getStandardErrorMessage,+} from "@/client/lib/error-messages";+import { BILLING_ROUTE } from "@/shared/billing";import { PageLoading } from "./Spinner";-/** A load failure with a retry button. The message goes through `getStandardErrorMessage`. */+/**+ * A load failure with a retry button. The message goes through+ * `getStandardErrorMessage`. Out of credits, a retry can't succeed, so the+ * button goes to Billing instead.+ */export function QueryError({error,+ cause,fallback,onRetry,isRetrying = false,}: {/** Omit to always show `fallback`, for errors the page words itself. */error?: unknown;+ /** The error behind a `fallback` the page words itself; picks the button. */+ cause?: unknown;/** Shown when the error has no message of its own. */fallback: string;onRetry?: () => void;@@ -22,7 +34,11 @@ export function QueryError({<span className="text-sm">{getStandardErrorMessage(error, fallback)}</span>- {onRetry ? (+ {getErrorCode(error ?? cause) === "INSUFFICIENT_CREDITS" ? (+ <Link to={BILLING_ROUTE} className="btn btn-sm">+ Go to Billing+ </Link>+ ) : onRetry ? (<buttontype="button"className="btn btn-sm"diff --git a/src/client/features/ai-search/BrandLookupPage.tsx b/src/client/features/ai-search/BrandLookupPage.tsxindex 498de5ec..2af9e648 100644--- a/src/client/features/ai-search/BrandLookupPage.tsx+++ b/src/client/features/ai-search/BrandLookupPage.tsx@@ -289,6 +289,7 @@ export function BrandLookupPage({{errorMessage ? (<QueryError+ cause={lookupQuery.error}fallback={resultData? `${errorMessage} Showing earlier results.`diff --git a/src/client/features/ai-search/PromptExplorerPage.tsx b/src/client/features/ai-search/PromptExplorerPage.tsxindex 9ca3a4ab..170daa99 100644--- a/src/client/features/ai-search/PromptExplorerPage.tsx+++ b/src/client/features/ai-search/PromptExplorerPage.tsx@@ -222,6 +222,7 @@ export function PromptExplorerPage({ projectId, urlState, onSubmit }: Props) {{errorMessage ? (<QueryError+ cause={exploreQuery.error}fallback={resultData? `${errorMessage} Showing earlier results.`diff --git a/src/client/features/backlinks/BacklinksPageContent.tsx b/src/client/features/backlinks/BacklinksPageContent.tsxindex 76d316ea..27500c51 100644--- a/src/client/features/backlinks/BacklinksPageContent.tsx+++ b/src/client/features/backlinks/BacklinksPageContent.tsx@@ -175,6 +175,9 @@ export function BacklinksBody({// them because the query never ran for the current filters.showTable={activeTabPage !== undefined && !data.activeTabFilterError}tabErrorMessage={data.activeTabErrorMessage}+ tabError={+ data.activeTabFilterError ? undefined : data.activeTabQuery.error+ }onRetryTab={data.activeTabFilterError? undefineddiff --git a/src/client/features/backlinks/BacklinksPageSections.tsx b/src/client/features/backlinks/BacklinksPageSections.tsxindex 431d151b..22339b9f 100644--- a/src/client/features/backlinks/BacklinksPageSections.tsx+++ b/src/client/features/backlinks/BacklinksPageSections.tsx@@ -52,6 +52,7 @@ export function BacklinksResultsCard({isTabLoading,showTable,tabErrorMessage,+ tabError,onRetryTab,isTabRetrying,exportTarget,@@ -75,6 +76,7 @@ export function BacklinksResultsCard({isTabLoading: boolean;showTable: boolean;tabErrorMessage: string | null;+ tabError?: unknown;onRetryTab?: () => void;isTabRetrying: boolean;exportTarget: string;@@ -265,6 +267,7 @@ export function BacklinksResultsCard({{tabErrorMessage ? (<div className="mb-3"><QueryError+ cause={tabError}fallback={tabErrorMessage}onRetry={onRetryTab}isRetrying={isTabRetrying}diff --git a/src/client/features/billing/route-state.test.ts b/src/client/features/billing/route-state.test.tsindex 18b9b961..e1e2c098 100644--- a/src/client/features/billing/route-state.test.ts+++ b/src/client/features/billing/route-state.test.ts@@ -8,6 +8,7 @@ describe("getSubscribeRouteState", () => {hasSession: true,isCustomerLoading: false,isCustomerError: false,+ hasCustomerData: true,hasManagedAccess: true,planStatus: "free" as const,isUpgradeFlow: false,@@ -49,6 +50,15 @@ describe("getSubscribeRouteState", () => {).toBe("finalizing");});+ it("keeps the paywall when a customer refetch fails, but not a first load", () => {+ const failed = { ...base, isUpgradeFlow: true, isCustomerError: true };++ expect(getSubscribeRouteState(failed)).toBe("showPaywall");+ expect(getSubscribeRouteState({ ...failed, hasCustomerData: false })).toBe(+ "error",+ );+ });+it("lets the user through once the finalizing window runs out", () => {expect(getSubscribeRouteState({diff --git a/src/client/features/billing/route-state.ts b/src/client/features/billing/route-state.tsindex 131383bd..5b2651cb 100644--- a/src/client/features/billing/route-state.ts+++ b/src/client/features/billing/route-state.ts@@ -23,6 +23,7 @@ export function getSubscribeRouteState(args: {hasSession: boolean;isCustomerLoading: boolean;isCustomerError: boolean;+ hasCustomerData: boolean;hasManagedAccess: boolean;planStatus: PlanStatus;isUpgradeFlow: boolean;@@ -42,8 +43,14 @@ export function getSubscribeRouteState(args: {}// A failed poll while finalizing keeps polling: the error screen would stop- // the poll and park a just-paid user on "Billing unavailable".- if (args.isCustomerError && !args.checkoutCompleted) {+ // the poll and park a just-paid user on "Billing unavailable". A failed+ // refetch with the customer already loaded keeps the paywall, since every+ // Upgrade button in the app lands here.+ if (+ args.isCustomerError &&+ !args.checkoutCompleted &&+ !args.hasCustomerData+ ) {return "error" as const;}diff --git a/src/client/features/dashboard/DashboardCards.tsx b/src/client/features/dashboard/DashboardCards.tsxindex 4327a7fb..165a4c11 100644--- a/src/client/features/dashboard/DashboardCards.tsx+++ b/src/client/features/dashboard/DashboardCards.tsx@@ -161,19 +161,23 @@ export function AuditHealthCard({</Link>}>- {audit.status !== "completed" ? (- // A running or failed crawl has at most a partial issue list, and an- // empty one is not the same as a healthy site.+ {audit.status === "running" ? (+ // A running crawl has at most a partial issue list, and an empty one+ // is not the same as a healthy site.<p className="text-sm text-base-content/70">- {audit.status === "running"- ? "Issues appear here when the crawl finishes."- : "Run the audit again to see issues."}+ Issues appear here when the crawl finishes.</p>) : audit.topIssues.length === 0 ? (- <div className="flex items-center gap-2 text-sm text-base-content/70">- <Check className="size-4 text-success" />- No issues found — your site looks healthy.- </div>+ audit.status === "completed" ? (+ <div className="flex items-center gap-2 text-sm text-base-content/70">+ <Check className="size-4 text-success" />+ No issues found — your site looks healthy.+ </div>+ ) : (+ <p className="text-sm text-base-content/70">+ Run the audit again to see issues.+ </p>+ )) : (<ul className="space-y-2">{audit.topIssues.map((issue) => (@@ -206,6 +210,12 @@ export function AuditHealthCard({{audit.totalIssueTypes - audit.topIssues.length === 1 ? "" : "s"}</li>) : null}+ {/* A failed crawl keeps what it found, as the audit page does. */}+ {audit.status !== "completed" ? (+ <li className="text-xs text-base-content/50">+ From the pages crawled before the audit stopped.+ </li>+ ) : null}</ul>)}</CardShell>diff --git a/src/client/features/rank-tracking/RankTrackingTableToolbar.tsx b/src/client/features/rank-tracking/RankTrackingTableToolbar.tsxindex 1576aa01..27e8bc4e 100644--- a/src/client/features/rank-tracking/RankTrackingTableToolbar.tsx+++ b/src/client/features/rank-tracking/RankTrackingTableToolbar.tsx@@ -116,15 +116,18 @@ export function RankTrackingTableToolbar({hasData={hasData}/>- <MoreMenu- onCheckNow={onCheckNow}- checkBusy={checkBusy}- checkDisabled={checkDisabled}- onRefreshMetrics={onRefreshMetrics}- metricsRefreshing={metricsRefreshing}- trackedKeywordCount={trackedKeywordCount}- hasData={hasData}- />+ {/* Both actions need a paid plan; free users get the page's upgrade+ alert instead of a menu whose items fail. */}+ {!checkDisabled && (+ <MoreMenu+ onCheckNow={onCheckNow}+ checkBusy={checkBusy}+ onRefreshMetrics={onRefreshMetrics}+ metricsRefreshing={metricsRefreshing}+ trackedKeywordCount={trackedKeywordCount}+ hasData={hasData}+ />+ )}</div>);}diff --git a/src/client/features/rank-tracking/ToolbarMenus.tsx b/src/client/features/rank-tracking/ToolbarMenus.tsxindex 441fdd4f..0a5fb292 100644--- a/src/client/features/rank-tracking/ToolbarMenus.tsx+++ b/src/client/features/rank-tracking/ToolbarMenus.tsx@@ -89,7 +89,6 @@ function MenuItem({export function MoreMenu({onCheckNow,checkBusy,- checkDisabled,onRefreshMetrics,metricsRefreshing,trackedKeywordCount,@@ -97,7 +96,6 @@ export function MoreMenu({}: {onCheckNow: () => void;checkBusy: boolean;- checkDisabled: boolean;onRefreshMetrics: () => void;metricsRefreshing: boolean;trackedKeywordCount: number;@@ -110,15 +108,13 @@ export function MoreMenu({icon={<MoreHorizontal className="size-4" />}title="More actions">- {!checkDisabled && (- <MenuItem- icon={<Play className="size-3.5" />}- label={checkBusy ? "Running..." : "Check rankings"}- description="Fetch current Google positions"- onClick={onCheckNow}- disabled={checkBusy}- />- )}+ <MenuItem+ icon={<Play className="size-3.5" />}+ label={checkBusy ? "Running..." : "Check rankings"}+ description="Fetch current Google positions"+ onClick={onCheckNow}+ disabled={checkBusy}+ /><MenuItemicon={<RefreshCwdiff --git a/src/client/features/sam/SamChat.tsx b/src/client/features/sam/SamChat.tsxindex 430a4d12..ac864c0b 100644--- a/src/client/features/sam/SamChat.tsx+++ b/src/client/features/sam/SamChat.tsx@@ -25,27 +25,28 @@ export function SamChat({}) {const optedIn = useSamBetaOptIn();const access = useSamAccess(projectId);- const { sessionsQuery, sessions, goToSession, createSession } =- useSamSessions(projectId, { replace: true });// The ref (not isPending) guards the auto-create below: React can re-run the// 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 per-call callbacks fire for the create started from- // the effect below, but the hook's `isError` can miss it and leave the+ // 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 { sessionsQuery, sessions, goToSession, createSession } =+ useSamSessions(projectId, {+ replace: true,+ onCreateError: setCreateError,+ onCreateSettled: () => {+ creating.current = false;+ },+ });const { mutate: createSessionMutate } = createSession;const startChat = useCallback(() => {creating.current = true;setCreateError(null);- createSessionMutate(undefined, {- onError: setCreateError,- onSettled: () => {- creating.current = false;- },- });+ createSessionMutate();}, [createSessionMutate]);// Landing without a session: open the most recent one, or start a freshdiff --git a/src/client/features/sam/SamSidebarPanel.tsx b/src/client/features/sam/SamSidebarPanel.tsxindex 8a0b4eee..0882bb0a 100644--- a/src/client/features/sam/SamSidebarPanel.tsx+++ b/src/client/features/sam/SamSidebarPanel.tsx@@ -1,6 +1,7 @@-import { useLocation } from "@tanstack/react-router";+import { Link, useLocation } from "@tanstack/react-router";import { useMutation, useQueryClient } from "@tanstack/react-query";-import { Archive, Loader2, Plus } from "lucide-react";+import { useEffect, useState } from "react";+import { Archive, Loader2, Plus, X } from "lucide-react";import { archiveSamSession } from "@/serverFunctions/sam";import {invalidateSamSessions,@@ -10,6 +11,46 @@ import { QueryState } from "@/client/components/QueryState";import { useSamBetaOptIn } from "./samBetaOptIn";import { useSamSessions } from "./useSamSessions";+const BETA_NOTICE_DISMISSED_KEY = "sam-beta-notice-dismissed";++// The MCP nudge for users who already opted into SAM: SamBetaGate carries it+// before opt-in, and this card keeps it in view afterwards. Dismissible per+// browser; localStorage is read in an effect so SSR and the first client+// render stay identical.+function BetaNotice() {+ const [dismissed, setDismissed] = useState(true);+ useEffect(() => {+ setDismissed(localStorage.getItem(BETA_NOTICE_DISMISSED_KEY) === "1");+ }, []);+ if (dismissed) return null;++ return (+ <div className="mx-2 mb-2 rounded-lg border border-base-300 bg-base-100 p-3">+ <div className="flex items-center justify-between">+ <span className="badge badge-primary badge-sm">Beta</span>+ <button+ type="button"+ aria-label="Dismiss"+ className="btn btn-ghost btn-xs btn-square text-base-content/40"+ onClick={() => {+ localStorage.setItem(BETA_NOTICE_DISMISSED_KEY, "1");+ setDismissed(true);+ }}+ >+ <X className="size-3.5" />+ </button>+ </div>+ <p className="mt-1.5 text-xs text-base-content/70">+ For more powerful AI workflows, use the OpenSEO MCP with your own agent+ like Claude Code or Hermes.+ </p>+ <Link to="/ai" className="link link-primary mt-1.5 inline-block text-xs">+ Set up the MCP →+ </Link>+ </div>+ );+}+// Compact age label for the session list (PostHog-style "3h" / "12d").// Timestamps come back as UTC from both backends: D1 as "YYYY-MM-DD HH:MM:SS"// (no zone marker), Postgres as ISO-8601 with a trailing Z.@@ -145,6 +186,8 @@ export function SamSidebarPanel({}</QueryState></div>++ <BetaNotice /></div>);}diff --git a/src/client/features/sam/useSamSessions.ts b/src/client/features/sam/useSamSessions.tsindex 420a3c94..20e5efe7 100644--- a/src/client/features/sam/useSamSessions.ts+++ b/src/client/features/sam/useSamSessions.ts@@ -18,7 +18,14 @@ export function useSamSessions({replace = false,onNavigate,- }: { replace?: boolean; onNavigate?: () => void } = {},+ onCreateError,+ onCreateSettled,+ }: {+ replace?: boolean;+ onNavigate?: () => void;+ onCreateError?: (error: Error) => void;+ onCreateSettled?: () => void;+ } = {},) {const navigate = useNavigate();const sessionsQuery = useQuery(samSessionsQueryOptions(projectId));@@ -44,6 +51,12 @@ export function useSamSessions(await invalidateSamSessions(projectId);goToSession(id);},+ // On the mutation, not per call: per-call callbacks go through the+ // observer and are skipped when it detaches (StrictMode's double mount).+ // Passing onCreateError also keeps the global error toast quiet, since+ // the caller shows the error itself.+ onError: onCreateError,+ onSettled: onCreateSettled,});return {diff --git a/src/routes/_app/p/$projectId/reports/$reportId.tsx b/src/routes/_app/p/$projectId/reports/$reportId.tsxindex 5b68db44..046cf5ed 100644--- a/src/routes/_app/p/$projectId/reports/$reportId.tsx+++ b/src/routes/_app/p/$projectId/reports/$reportId.tsx@@ -262,8 +262,9 @@ function ReportDetailPage() {They belong to the viewer, not the document, so they overlay theiframe instead of being injected into it. Placed before the iframeso keyboard focus reaches them without tabbing through the report;- inset from the edge so they clear a classic scrollbar. */}- <div className="absolute top-1 right-5 flex items-center gap-0.5 rounded-md border border-base-300 bg-base-100/95 p-0.5 shadow-sm backdrop-blur">+ inset from the edge so they clear a classic scrollbar. z-10 keeps+ them above the viewer, which is positioned and comes later. */}+ <div className="absolute top-1 right-5 z-10 flex items-center gap-0.5 rounded-md border border-base-300 bg-base-100/95 p-0.5 shadow-sm backdrop-blur"><buttontype="button"className="btn btn-ghost btn-sm btn-square"diff --git a/src/routes/_authenticated.subscribe.tsx b/src/routes/_authenticated.subscribe.tsxindex 5d93c315..a759cc45 100644--- a/src/routes/_authenticated.subscribe.tsx+++ b/src/routes/_authenticated.subscribe.tsx@@ -77,6 +77,7 @@ function SubscribePage() {hasSession,isCustomerLoading: customerQuery.isLoading,isCustomerError: customerQuery.isError,+ hasCustomerData: customerQuery.data != null,hasManagedAccess,planStatus,isUpgradeFlow: isUpgradeFlow === true,