import { homepageScarfPixel } from '~/utils/analytics/scarf-pixels' import * as React from 'react' import { Link, createFileRoute } from '@tanstack/react-router' import { twMerge } from 'tailwind-merge' import { ArrowRightIcon, CodeIcon, StackIcon, ShieldIcon, LightningIcon, type Icon, } from '@phosphor-icons/react' import { HeroPalmMedia } from '~/components/home/HeroPalmMedia' import { HomeApplicationStarter } from '~/components/home/HomeApplicationStarter' import { HomeCommunitySection } from '~/components/home/HomeCommunitySection' import { HomeNewsletterSection } from '~/components/home/HomeNewsletterSection' import { HomeSocialProofSection } from '~/components/home/HomeSocialProofSection' import { HomeStatsSection } from '~/components/home/HomeStatsSection' import { HomeStatNumber } from '~/components/home/HomeStatNumber' import { LiveDownloadCount } from '~/components/home/LiveDownloadCount' import { useQuery } from '@tanstack/react-query' import { Button } from '~/components/ds/ui' import { Scarf } from '~/components/Scarf' import { useInView } from '~/hooks/useInView' import { homepageNpmStatsSummaryQuery, ossStatsQuery } from '~/queries/stats' import { useLibrariesOverlay } from '~/contexts/LibrariesOverlayContext' import { fetchRecentPosts } from '~/utils/blog.functions' import { usePrefersReducedMotion } from '~/utils/usePrefersReducedMotion' import { seo } from '~/utils/seo' import { getTanStackHomepageJsonLd } from '~/utils/organization-structured-data' export const Route = createFileRoute('/')({ loader: async ({ context: { queryClient } }) => { const npmStatsQuery = homepageNpmStatsSummaryQuery() const [stats, npmSummary, recentPosts] = await Promise.all([ queryClient.ensureQueryData(ossStatsQuery()), queryClient.ensureQueryData(npmStatsQuery), fetchRecentPosts(), ]) return { recentPosts, initialStats: { totalDownloads: npmSummary?.totalDownloads ?? stats.npm?.totalDownloads, weeklyDownloads: npmSummary?.weeklyDownloads, weeklyRatePerDay: npmSummary?.weeklyRatePerDay, npmStatsFetchedAt: queryClient.getQueryState(npmStatsQuery.queryKey)?.dataUpdatedAt ?? 0, starCount: stats.github?.starCount, }, } }, head: () => ({ meta: seo({ title: 'TanStack | The open-source application stack for the web.', description: 'Headless, type-safe, composable tools for building modern web applications that work naturally for developers and reliably for agents.', }), scripts: [ { type: 'application/ld+json', children: JSON.stringify(getTanStackHomepageJsonLd()), }, ], }), component: Index, }) function Index() { const { initialStats, recentPosts } = Route.useLoaderData() const { openLibraries } = useLibrariesOverlay() const startWithPrompt = (e: React.MouseEvent) => { e.preventDefault() const section = document.getElementById('start-with-a-prompt') section?.scrollIntoView({ behavior: 'smooth', block: 'start' }) const field = section?.querySelector('textarea') field?.focus({ preventScroll: true }) field?.select() } return ( <>
{/* Hero — Figma node 802:2027. Full-bleed palm and sky: headline bottom-left, description + CTA bottom-right. The sky is always light, so text uses a mode-stable dark token (neutral-500) rather than a theme-flipping semantic. */}
{/* The small viewport height keeps the hero stable as mobile browser chrome collapses. */}

The{' '} open source
application stack
for the web

Headless, type-safe, composable tools for building modern web applications that work naturally for developers and reliably for agents

{/* The sky is always light, so scope the CTAs to the DS light mode — the Buttons then render as their standard DS light-mode selves (no per-button color overrides). */}
) } type PrincipleProof = 'adapters' | 'types' | 'adoption' | 'portable' type WhyTanStackPrinciple = { title: string body: string Icon: Icon accentClassName: string iconClassName: string proof: PrincipleProof } type AdapterGraphNode = { height: number label: string width: number x: number y: number } type AdapterGraphPoint = { x: number y: number } type AdapterGraphCurve = { control1: AdapterGraphPoint control2: AdapterGraphPoint path: string } // Accent hues come from the DS palette (--color-ds-*), not the library // `category-*` tokens: these are product principles, not library categories. // Figma specifies near-neighbours of these values (e.g. #d3481b vs the DS // terracotta-400 #c3502b); the DS token wins per the design-system-first rule. const whyTanStackPrinciples = [ { title: 'Framework Agnostic', body: 'Our library cores are provider-agnostic and logic-driven, meaning you can use the same logic in React, Vue, Svelte, Solid, and more.', Icon: StackIcon, accentClassName: 'from-blue-500 to-cyan-500', iconClassName: 'border-cyan-200 bg-cyan-50 text-cyan-700 dark:border-cyan-900 dark:bg-cyan-950/40 dark:text-cyan-300', proof: 'adapters', }, { title: 'Type-Safe by Design', body: 'Built with TypeScript from the ground up, providing incredible autocomplete and safety across your entire data-fetching and state management stack.', Icon: CodeIcon, accentClassName: 'from-emerald-500 to-teal-500', iconClassName: 'border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300', proof: 'types', }, { title: 'Production-Grade', body: "Battle-tested in the world's largest apps. We build for scale, handling complex concurrency, caching, and state synchronization with ease.", Icon: LightningIcon, accentClassName: 'from-orange-500 to-red-500', iconClassName: 'border-orange-200 bg-orange-50 text-orange-700 dark:border-orange-900 dark:bg-orange-950/40 dark:text-orange-300', proof: 'adoption', }, { title: 'No Vendor Lock-in', body: "Open source and independent. We aren't beholden to any single cloud provider or framework team, ensuring the best tools for the community.", Icon: ShieldIcon, accentClassName: 'from-purple-500 to-pink-500', iconClassName: 'border-purple-200 bg-purple-50 text-purple-700 dark:border-purple-900 dark:bg-purple-950/40 dark:text-purple-300', proof: 'portable', }, ] satisfies ReadonlyArray const adapterGraphWidth = 320 const adapterGraphHeight = 128 const frameworkAdapterCore = { label: 'core', x: 132, y: 58, width: 56, height: 32, } satisfies AdapterGraphNode const frameworkAdapterNodes = [ { label: 'React', x: 18, y: 28, width: 60, height: 26 }, { label: 'Vue', x: 132, y: 7, width: 56, height: 26 }, { label: 'Solid', x: 242, y: 28, width: 60, height: 26 }, { label: 'Angular', x: 26, y: 98, width: 78, height: 26 }, { label: 'Vanilla', x: 216, y: 98, width: 78, height: 26 }, ] satisfies ReadonlyArray const frameworkAdapterConnections = frameworkAdapterNodes.map((node) => { const start = edgeAnchor(frameworkAdapterCore, node) const end = edgeAnchor(node, frameworkAdapterCore) const curve = curveBetween(start, end, 0.5) return { control1: curve.control1, control2: curve.control2, end, label: node.label, path: curve.path, start, } }) function centerPoint(node: AdapterGraphNode): AdapterGraphPoint { return { x: node.x + node.width / 2, y: node.y + node.height / 2, } } function edgeAnchor( node: AdapterGraphNode, toward: AdapterGraphNode, ): AdapterGraphPoint { const center = centerPoint(node) const targetCenter = centerPoint(toward) const deltaX = targetCenter.x - center.x const deltaY = targetCenter.y - center.y if (deltaX === 0 && deltaY === 0) { return center } const scaleX = deltaX === 0 ? Number.POSITIVE_INFINITY : node.width / 2 / Math.abs(deltaX) const scaleY = deltaY === 0 ? Number.POSITIVE_INFINITY : node.height / 2 / Math.abs(deltaY) const scale = Math.min(scaleX, scaleY) return { x: center.x + deltaX * scale, y: center.y + deltaY * scale, } } function curveBetween( start: AdapterGraphPoint, end: AdapterGraphPoint, bend = 0.5, ): AdapterGraphCurve { if (Math.abs(end.y - start.y) > Math.abs(end.x - start.x)) { const controlY = start.y + (end.y - start.y) * bend const control1 = { x: start.x, y: controlY } const control2 = { x: end.x, y: controlY } return { control1, control2, path: `M ${start.x} ${start.y} C ${control1.x} ${control1.y}, ${control2.x} ${control2.y}, ${end.x} ${end.y}`, } } const controlX = start.x + (end.x - start.x) * bend const control1 = { x: controlX, y: start.y } const control2 = { x: controlX, y: end.y } return { control1, control2, path: `M ${start.x} ${start.y} C ${control1.x} ${control1.y}, ${control2.x} ${control2.y}, ${end.x} ${end.y}`, } } function adapterGraphStyle(node: AdapterGraphNode): React.CSSProperties { return { height: `${(node.height / adapterGraphHeight) * 100}%`, left: `${(node.x / adapterGraphWidth) * 100}%`, top: `${(node.y / adapterGraphHeight) * 100}%`, width: `${(node.width / adapterGraphWidth) * 100}%`, } } function adapterGraphPointStyle(point: AdapterGraphPoint): React.CSSProperties { return { left: `${(point.x / adapterGraphWidth) * 100}%`, top: `${(point.y / adapterGraphHeight) * 100}%`, } } function cubicPoint( start: AdapterGraphPoint, control1: AdapterGraphPoint, control2: AdapterGraphPoint, end: AdapterGraphPoint, progress: number, ): AdapterGraphPoint { const inverse = 1 - progress return { x: inverse ** 3 * start.x + 3 * inverse ** 2 * progress * control1.x + 3 * inverse * progress ** 2 * control2.x + progress ** 3 * end.x, y: inverse ** 3 * start.y + 3 * inverse ** 2 * progress * control1.y + 3 * inverse * progress ** 2 * control2.y + progress ** 3 * end.y, } } function cubicAngle( start: AdapterGraphPoint, control1: AdapterGraphPoint, control2: AdapterGraphPoint, end: AdapterGraphPoint, progress: number, ): number { const inverse = 1 - progress const deltaX = 3 * inverse ** 2 * (control1.x - start.x) + 6 * inverse * progress * (control2.x - control1.x) + 3 * progress ** 2 * (end.x - control2.x) const deltaY = 3 * inverse ** 2 * (control1.y - start.y) + 6 * inverse * progress * (control2.y - control1.y) + 3 * progress ** 2 * (end.y - control2.y) return (Math.atan2(deltaY, deltaX) * 180) / Math.PI } /** * The "Why TanStack?" principles stack — Figma 478:1734. * * On desktop, the stack is 960px wide. Each card has 233px of content with * 24px of padding above and below and a 70px gap between the two columns. */ function WhyTanStackSection() { return (

Why TanStack?

{/* features-stack — 478:1742 */}
    {whyTanStackPrinciples.map((principle, index) => (
  1. {/* copy column — 478:1745. Everything is left-aligned to the card edge; at desktop sizes the title and description stay grouped at the center of the 233px proof panel. */}

    {principle.title}

    {principle.body}

    {/* proof panel — 478:1744 */}
  2. ))}
{/* Quiet corner CTA — hugs the bottom-right of the section. Muted at rest so it doesn't compete with the stack; on hover the label brightens and the arrow slides to afford that it goes somewhere. */}
Read our product tenets
) } /** * The 460×233 proof slot from Figma (478:1744 et al). * * Deliberately chrome-less: no border, no fill. The design draws a surface * here, but the proofs read better floating directly on the card — the row * dividers and the 70px gutter already separate them from the copy, so a * second frame around each one was redundant weight. */ function PrinciplePanel({ children }: { children: React.ReactNode }) { return (
{children}
) } function FrameworkAdapterGraph({ accentClassName, }: { accentClassName: string }) { const [activeAdapterIndex, setActiveAdapterIndex] = React.useState(0) const [flowProgress, setFlowProgress] = React.useState(0) const rootRef = React.useRef(null) const isVisible = useInView(rootRef) const prefersReducedMotion = usePrefersReducedMotion() React.useEffect(() => { if (!isVisible || prefersReducedMotion !== false) return const intervalId = window.setInterval(() => { setActiveAdapterIndex( (currentIndex) => (currentIndex + 1) % frameworkAdapterNodes.length, ) }, 1150) return () => window.clearInterval(intervalId) }, [isVisible, prefersReducedMotion]) React.useEffect(() => { if (!isVisible || prefersReducedMotion !== false) return let frameId = 0 let lastUpdate = 0 const duration = 1500 const update = (timestamp: number) => { if (timestamp - lastUpdate > 33) { setFlowProgress((timestamp % duration) / duration) lastUpdate = timestamp } frameId = window.requestAnimationFrame(update) } frameId = window.requestAnimationFrame(update) return () => window.cancelAnimationFrame(frameId) }, [isVisible, prefersReducedMotion]) return ( // The node positions below are hard-coded against a 320×128 grid // (adapterGraphWidth/Height), so the whole graph is scaled as a unit rather // than re-deriving every coordinate. The scale tracks the wrapper's own // width, so the graph fills whatever slot it lands in without restating the // ancestors' padding. The 1.35 cap is the ratio the fixed 460px `lg` slot // was designed around.
) } function PrincipleProof({ proof, accentClassName, }: { proof: PrincipleProof accentClassName: string }) { if (proof === 'adapters') { return } if (proof === 'types') { return (
{[ ['params.postId', 'string'], ['query.data', 'Project[]'], ['form.email', 'Field'], ].map(([name, value]) => (
{name} {value}
))}
) } if (proof === 'adoption') { return } return } function AdoptionProof() { const { initialStats } = Route.useLoaderData() const { data: summary, dataUpdatedAt } = useQuery( homepageNpmStatsSummaryQuery(), ) const { data: stats } = useQuery(ossStatsQuery()) const totalDownloads = summary?.totalDownloads ?? initialStats.totalDownloads ?? 0 const weeklyDownloads = summary?.weeklyDownloads ?? initialStats.weeklyDownloads ?? 0 const starCount = stats?.github?.starCount ?? initialStats.starCount ?? 0 const liveDownloads = { ratePerDay: summary?.weeklyRatePerDay ?? initialStats.weeklyRatePerDay ?? 0, fetchedAt: dataUpdatedAt || initialStats.npmStatsFetchedAt, } return (
npm downloads {totalDownloads > 0 ? ( ) : ( '—' )}
{[ { label: 'per week', value: weeklyDownloads > 0 ? ( ) : ( '—' ), }, { label: 'github stars', value: starCount > 0 ? : '—', }, ].map(({ label, value }) => (
{label} {value}
))}
) } /** * No Vendor Lock-in proof: the same four claims the chip list made, but as a * checked ledger so the panel reads as substantiated rather than decorative. */ function IndependenceProof({ accentClassName }: { accentClassName: string }) { return (
{[ ['license', 'MIT'], ['hosting', 'self-host anywhere'], ['governance', 'community-driven'], ['paid tiers', 'none'], ].map(([term, value], index) => (
0 && 'border-t border-gray-200/70 dark:border-gray-800/70', )} >
{term}
{value}
))}
) }