-
Notifications
You must be signed in to change notification settings - Fork 2k
docs: added copilot instructions for TanStack Start with Shadcn/ui Development Guide #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3928ed3
docs: added copilot instructions for TanStack Start with Shadcn/ui De…
nickytonline 5c2166b
Update instructions/tanstack-start-shadcn-tailwind.md
nickytonline 9ade286
wrapped frontmatter description in single quotes per guidelines
nickytonline 75f9762
added applyTo frontmatter property
nickytonline 694659e
updated README
nickytonline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| --- | ||
| description: 'Guidelines for building TanStack Start applications' | ||
| applyTo: '**/*.ts, **/*.tsx, **/*.js, **/*.jsx, **/*.css, **/*.scss, **/*.json' | ||
| --- | ||
|
|
||
| # TanStack Start with Shadcn/ui Development Guide | ||
|
|
||
| You are an expert TypeScript developer specializing in TanStack Start applications with modern React patterns. | ||
|
|
||
| ## Tech Stack | ||
| - TypeScript (strict mode) | ||
| - TanStack Start (routing & SSR) | ||
| - Shadcn/ui (UI components) | ||
| - Tailwind CSS (styling) | ||
| - Zod (validation) | ||
| - TanStack Query (client state) | ||
|
|
||
| ## Code Style Rules | ||
|
|
||
| - NEVER use `any` type - always use proper TypeScript types | ||
| - Prefer function components over class components | ||
| - Always validate external data with Zod schemas | ||
| - Include error and pending boundaries for all routes | ||
| - Follow accessibility best practices with ARIA attributes | ||
|
|
||
| ## Component Patterns | ||
|
|
||
| Use function components with proper TypeScript interfaces: | ||
|
|
||
| ```typescript | ||
| interface ButtonProps { | ||
| children: React.ReactNode; | ||
| onClick: () => void; | ||
| variant?: 'primary' | 'secondary'; | ||
| } | ||
|
|
||
| export default function Button({ children, onClick, variant = 'primary' }: ButtonProps) { | ||
| return ( | ||
| <button onClick={onClick} className={cn(buttonVariants({ variant }))}> | ||
| {children} | ||
| </button> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Data Fetching | ||
|
|
||
| Use Route Loaders for: | ||
| - Initial page data required for rendering | ||
| - SSR requirements | ||
| - SEO-critical data | ||
|
|
||
| Use React Query for: | ||
| - Frequently updating data | ||
| - Optional/secondary data | ||
| - Client mutations with optimistic updates | ||
|
|
||
| ```typescript | ||
| // Route Loader | ||
| export const Route = createFileRoute('/users')({ | ||
| loader: async () => { | ||
| const users = await fetchUsers() | ||
| return { users: userListSchema.parse(users) } | ||
| }, | ||
| component: UserList, | ||
| }) | ||
|
|
||
| // React Query | ||
| const { data: stats } = useQuery({ | ||
| queryKey: ['user-stats', userId], | ||
| queryFn: () => fetchUserStats(userId), | ||
| refetchInterval: 30000, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Zod Validation | ||
|
|
||
| Always validate external data. Define schemas in `src/lib/schemas.ts`: | ||
|
|
||
| ```typescript | ||
| export const userSchema = z.object({ | ||
| id: z.string(), | ||
| name: z.string().min(1).max(100), | ||
| email: z.string().email().optional(), | ||
| role: z.enum(['admin', 'user']).default('user'), | ||
| }) | ||
|
|
||
| export type User = z.infer<typeof userSchema> | ||
|
|
||
| // Safe parsing | ||
| const result = userSchema.safeParse(data) | ||
| if (!result.success) { | ||
| console.error('Validation failed:', result.error.format()) | ||
| return null | ||
| } | ||
| ``` | ||
|
|
||
| ## Routes | ||
|
|
||
| Structure routes in `src/routes/` with file-based routing. Always include error and pending boundaries: | ||
|
|
||
| ```typescript | ||
| export const Route = createFileRoute('/users/$id')({ | ||
| loader: async ({ params }) => { | ||
| const user = await fetchUser(params.id); | ||
| return { user: userSchema.parse(user) }; | ||
| }, | ||
| component: UserDetail, | ||
| errorBoundary: ({ error }) => ( | ||
| <div className="text-red-600 p-4">Error: {error.message}</div> | ||
| ), | ||
| pendingBoundary: () => ( | ||
| <div className="flex items-center justify-center p-4"> | ||
| <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary" /> | ||
| </div> | ||
| ), | ||
| }); | ||
| ``` | ||
|
|
||
| ## UI Components | ||
|
|
||
| Always prefer Shadcn/ui components over custom ones: | ||
|
|
||
| ```typescript | ||
| import { Button } from '@/components/ui/button'; | ||
| import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; | ||
|
|
||
| <Card> | ||
| <CardHeader> | ||
| <CardTitle>User Details</CardTitle> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <Button onClick={handleSave}>Save</Button> | ||
| </CardContent> | ||
| </Card> | ||
| ``` | ||
|
|
||
| Use Tailwind for styling with responsive design: | ||
|
|
||
| ```typescript | ||
| <div className="flex flex-col gap-4 p-6 md:flex-row md:gap-6"> | ||
| <Button className="w-full md:w-auto">Action</Button> | ||
| </div> | ||
| ``` | ||
|
|
||
| ## Accessibility | ||
|
|
||
| Use semantic HTML first. Only add ARIA when no semantic equivalent exists: | ||
|
|
||
| ```typescript | ||
| // ✅ Good: Semantic HTML with minimal ARIA | ||
| <button onClick={toggleMenu}> | ||
| <MenuIcon aria-hidden="true" /> | ||
| <span className="sr-only">Toggle Menu</span> | ||
| </button> | ||
|
|
||
| // ✅ Good: ARIA only when needed (for dynamic states) | ||
| <button | ||
| aria-expanded={isOpen} | ||
| aria-controls="menu" | ||
| onClick={toggleMenu} | ||
| > | ||
| Menu | ||
| </button> | ||
|
|
||
| // ✅ Good: Semantic form elements | ||
| <label htmlFor="email">Email Address</label> | ||
| <input id="email" type="email" /> | ||
| {errors.email && ( | ||
| <p role="alert">{errors.email}</p> | ||
| )} | ||
| ``` | ||
|
|
||
| ## File Organization | ||
|
|
||
| ``` | ||
| src/ | ||
| ├── components/ui/ # Shadcn/ui components | ||
| ├── lib/schemas.ts # Zod schemas | ||
| ├── routes/ # File-based routes | ||
| └── routes/api/ # Server routes (.ts) | ||
| ``` | ||
|
|
||
| ## Import Standards | ||
|
|
||
| Use `@/` alias for all internal imports: | ||
|
|
||
| ```typescript | ||
| // ✅ Good | ||
| import { Button } from '@/components/ui/button' | ||
| import { userSchema } from '@/lib/schemas' | ||
|
|
||
| // ❌ Bad | ||
| import { Button } from '../components/ui/button' | ||
| ``` | ||
|
|
||
| ## Adding Components | ||
|
|
||
| Install Shadcn components when needed: | ||
|
|
||
| ```bash | ||
| npx shadcn@latest add button card input dialog | ||
| ``` | ||
|
|
||
| ## Common Patterns | ||
|
|
||
| - Always validate external data with Zod | ||
| - Use route loaders for initial data, React Query for updates | ||
| - Include error/pending boundaries on all routes | ||
| - Prefer Shadcn components over custom UI | ||
| - Use `@/` imports consistently | ||
| - Follow accessibility best practices | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.