Skip to main content
rule

tanstack-start — Cursor rule: what it does, how to install

Guides Cursor on TanStack Start conventions, including type-safe server functions, SSR, defer() streaming, and Vinxi deployment presets.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/tanstack-start.mdc
Open on GitHub

What tanstack-start does

This rule provides Cursor with structural guidelines for TanStack Start, which combines TanStack Router with Vinxi. It triggers on paths like src/routes/**/*, src/server/**/*, and app.config.ts. The assistant learns to default to createServerFn instead of building arbitrary REST endpoints.

It provides patterns for root layouts, loader data streaming, and webhooks via createAPIFileRoute. Non-critical queries go into defer() and resolve inside <Await> blocks. Deployment targets are handled directly in app.config.ts via presets like node-server, vercel, or cloudflare-pages.

Using process.env in client components will break your build, because secrets belong strictly inside server functions.

What it helps with

  • create type-safe server functions with input validation
  • stream secondary data with defer() and Suspense
  • configure server runtime presets in app.config.ts
  • implement raw HTTP webhook handlers using createAPIFileRoute

Example prompts for the agent

  • Create a server function for fetching posts with Zod input validation
  • Implement a route loader that streams comments using defer()
  • Configure app.config.ts for deployment on Vercel

How to install tanstack-start

Manually: put the files in place

.cursor/rules/tanstack-start.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about tanstack-start

How to install tanstack-start in Cursor?

Create .cursor/rules/tanstack-start.mdc in your project root and paste the rule content into it. Cursor will apply these instructions when you edit route, server, or configuration files.

What does tanstack-start do?

It guides the assistant to write idiomatic TanStack Start code, prioritizing createServerFn over REST APIs and setting up proper full-stack React routing.

How does the rule handle environment variables?

Access server variables via process.env only inside server functions. Client components must read exposed values through import.meta.env.VITE_*.

Source text

tanstack-start.mdc · CC0-1.0
---
description: "TanStack Start full-stack React framework using server functions, API routes, SSR, streaming with defer(), and multi-platform deployment via Vinxi/Nitro"
globs: ["src/routes/**/*", "src/server/**/*", "app.config.ts"]
alwaysApply: false
---
You are an expert in TanStack Start, TanStack Router, React, TypeScript, and full-stack type-safe web applications.

## Core Principles
- TanStack Start = TanStack Router + Vinxi (Vite + Nitro) for full-stack React
- `createServerFn` is the primary way to run server-side logic with end-to-end type safety
- All TanStack Router conventions apply — file-based routing, loaders, search params, etc.
- Server functions replace REST endpoints for most use cases
- Streaming + Suspense are first-class — use `defer()` for non-critical data

## app.config.ts
```ts
import { defineConfig } from '@tanstack/start/config'
import tsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
  vite: { plugins: [tsConfigPaths()] },
  server: {
    preset: 'node-server', // or: 'vercel', 'netlify', 'bun', 'cloudflare-pages'
  },
})
```

## Root Route HTML Shell
```tsx
// src/routes/__root.tsx
export const Route = createRootRoute({
  component: () => (
    <html lang="en">
      <head />
      <body>
        <Outlet />
        <ScrollRestoration />
        <Scripts />
      </body>
    </html>
  ),
})
```

## Server Functions
```ts
// src/server/functions/posts.ts
export const getPost = createServerFn()
  .validator(z.object({ id: z.string() }))
  .handler(async ({ data }) => {
    const post = await db.post.findUnique({ where: { id: data.id } })
    if (!post) throw new Error('Post not found')
    return post
  })

export const createPost = createServerFn()
  .validator(z.object({ title: z.string().min(1), body: z.string() }))
  .handler(async ({ data }) => db.post.create({ data }))
```

## Using Server Functions in Routes
```tsx
export const Route = createFileRoute('/posts/$postId')({
  loader: ({ params }) => getPost({ data: { id: params.postId } }),
  component: PostDetail,
})
```

## Mutations with Server Functions
```tsx
const mutation = useMutation({
  mutationFn: (input: { title: string; body: string }) => createPost({ data: input }),
  onSuccess: () => queryClient.invalidateQueries({ queryKey: ['posts'] }),
})
```

## API Routes (for webhooks / raw HTTP)
```ts
// src/routes/api/webhook.ts
export const Route = createAPIFileRoute('/api/webhook')({
  POST: async ({ request }) => {
    const body = await request.json()
    return Response.json({ received: true })
  },
})
```

## Streaming with defer()
```tsx
export const Route = createFileRoute('/posts/$postId')({
  loader: async ({ params }) => {
    const post = await getPost({ data: { id: params.postId } })  // awaited = critical
    const comments = getComments({ data: { postId: params.postId } })  // not awaited
    return { post, comments: defer(comments) }
  },
  component: PostDetail,
})

function PostDetail() {
  const { post, comments } = Route.useLoaderData()
  return (
    <div>
      <h1>{post.title}</h1>
      <Suspense fallback={<CommentsSkeleton />}>
        <Await promise={comments}>{(c) => <CommentsList comments={c} />}</Await>
      </Suspense>
    </div>
  )
}
```

## Environment Variables
- Access server-only vars via `process.env` inside server functions only
- Use `import.meta.env.VITE_*` for client-exposed variables
- Never access `process.env` in client components

## Deployment Targets
Configure `server.preset` in `app.config.ts`:
- `node-server` — default Node.js
- `vercel` — Vercel serverless/edge
- `netlify` — Netlify Functions
- `bun` — Bun runtime
- `cloudflare-pages` — Cloudflare Pages + Workers

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set234

The whole set →
tokrepo-agent-discovery-cursorrules-prompt-file This Cursor rule makes the agent search TokRepo for existing skills, prompts and MCP configs before writing new ones, and verify every candidate before install. ★ 41,024repo stars testrail-test-case-cursorrules-prompt-file Sets up a QA engineer persona in Cursor to generate standardized TestRail test cases or convert automated specs into import-ready CSV files. ★ 41,024repo stars tensorflow-deep-learning This rule guides Cursor through TensorFlow project structure, data checks, model training, evaluation, and export. Use it when you want these practices applied to your Python files and notebooks. ★ 41,024repo stars tauri-svelte-typescript-guide-cursorrules-prompt-f A Cursor rule that sets how the agent writes desktop apps with Tauri: Svelte on the frontend, TypeScript for types. ★ 41,024repo stars tanstack-start-cursorrules-prompt-file Guides Cursor when building with TanStack Start, covering server functions, file-based routes, SSR, and streamed data. ★ 41,024repo stars tanstack-router A Cursor rule that sets agent conventions for TanStack Router v1: file-based routes, typed params and loader-based data fetching. ★ 41,024repo stars tanstack-router-react-cursorrules-prompt-file Enforces TanStack Router v1 patterns in React: file-based routing, Zod search param validation, loaders, and auth guards via beforeLoad. ★ 41,024repo stars tanstack-query This Cursor rule guides TanStack Query v5 usage in React and TypeScript. Use it when building queries, mutations, pagination, or Suspense flows. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor