Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

AGENTS.md

171 lines7.2 KB

1# AGENTS.md
2​
3## Project overview
4​
5TanStack Router is a type-safe router with built-in caching and URL state management for React and Solid applications. This monorepo contains two main products:
6​
7- **TanStack Router** - Core routing library with type-safe navigation, search params, and path params
8- **TanStack Start** - Full-stack framework built on top of TanStack Router
9​
10## Setup commands
11​
12- Install deps: `pnpm install`
13- Setup e2e testing: `pnpm exec playwright install`
14- Build packages: `pnpm build` (affected) or `pnpm build:all` (force all)
15- Start dev server: `pnpm dev`
16- Run tests: `pnpm test`
17​
18## Code style
19​
20- TypeScript strict mode with extensive type safety
21- Framework-agnostic core logic separated from React/Solid bindings
22- Type-safe routing with search params and path params
23- Use workspace protocol for internal dependencies (`workspace:*`)
24​
25## Dev environment tips
26​
27- This is a pnpm workspace monorepo with packages organized by functionality
28- Nx provides caching, affected testing, targeting, and parallel execution for efficiency
29- Use `npx nx show projects` to list all available packages
30- Target specific packages: `npx nx run @tanstack/react-router:test:unit`
31- Target multiple packages: `npx nx run-many --target=test:eslint --projects=@tanstack/history,@tanstack/router-core`
32- Run affected tests only: `npx nx affected --target=test:unit`
33- Exclude patterns: `npx nx run-many --target=test:unit --exclude="examples/**,e2e/**"`
34- Navigate to examples and run `pnpm dev` to test changes: `cd examples/react/basic && pnpm dev`
35- **Granular Vitest testing within packages:**
36 - Navigate first: `cd packages/react-router`
37 - Specific files: `npx vitest run tests/link.test.tsx tests/Scripts.test.tsx`
38 - Test patterns: `npx vitest run tests/ClientOnly.test.tsx -t "should render fallback"`
39 - Name patterns: `npx vitest run -t "navigation"` (all tests with "navigation" in name)
40 - Exclude patterns: `npx vitest run --exclude="**/*link*" tests/`
41 - List tests: `npx vitest list tests/link.test.tsx` or `npx vitest list` (all)
42 - Through nx: `npx nx run @tanstack/react-router:test:unit -- tests/ClientOnly.test.tsx`
43- **Available test targets per package:** `test:unit`, `test:types`, `test:eslint`, `test:build`, `test:perf`, `build`
44- **Testing strategy:** Package level (nx) β†’ File level (vitest) β†’ Test level (-t flag) β†’ Pattern level (exclude)
45​
46## Testing instructions
47​
48- **Critical**: Always run unit and type tests during development - do not proceed if they fail
49- **Test types:** `pnpm test:unit`, `pnpm test:types`, `pnpm test:eslint`, `pnpm test:e2e`, `pnpm test:build`
50- **Full CI suite:** `pnpm test:ci`
51- **Fix formatting:** `pnpm prettier:write`
52- **Efficient targeted testing workflow:**
53 1. **Affected only:** `npx nx affected --target=test:unit` (compares to main branch)
54 2. **Specific packages:** `npx nx run @tanstack/react-router:test:unit`
55 3. **Specific files:** `cd packages/react-router && npx vitest run tests/link.test.tsx`
56 4. **Specific patterns:** `npx vitest run tests/link.test.tsx -t "preloading"`
57- **Pro tips:**
58 - Use `npx vitest list` to explore available tests before running
59 - Use `-t "pattern"` to focus on specific functionality during development
60 - Use `--exclude` patterns to skip unrelated tests
61 - Combine nx package targeting with vitest file targeting for maximum precision
62- **Example workflow:** `npx nx run @tanstack/react-router:test:unit` β†’ `cd packages/react-router && npx vitest run tests/link.test.tsx` β†’ `npx vitest run tests/link.test.tsx -t "preloading"`
63​
64## PR instructions
65​
66- Always run `pnpm test:eslint`, `pnpm test:types`, and `pnpm test:unit` before committing
67- Test changes in relevant example apps: `cd examples/react/basic && pnpm dev`
68- Update corresponding documentation in `docs/` directory when adding features
69- Add or update tests for any code changes
70- Use internal docs links relative to `docs/` folder (e.g., `./guide/data-loading`)
71​
72## Package structure
73​
74**Core packages:**
75​
76- `packages/router-core/` - Framework-agnostic core router logic
77- `packages/react-router/`, `packages/solid-router/` - React/Solid bindings and components
78- `packages/history/` - Browser history management
79​
80**Tooling:**
81​
82- `packages/router-cli/` - CLI tools for code generation
83- `packages/router-generator/` - Route generation utilities
84- `packages/router-plugin/` - Universal bundler plugins (Vite, Webpack, ESBuild, Rspack)
85- `packages/virtual-file-routes/` - Virtual file routing system
86​
87**Developer experience:**
88​
89- `packages/router-devtools/`, `packages/*-router-devtools/` - Development tools
90- `packages/eslint-plugin-router/` - ESLint rules for router
91​
92**Validation adapters:**
93​
94- `packages/zod-adapter/`, `packages/valibot-adapter/`, `packages/arktype-adapter/`
95​
96**Start framework:**
97​
98- `packages/*-start/`, `packages/start-*/` - Full-stack framework packages
99​
100**Examples & testing:**
101​
102- `examples/react/`, `examples/solid/` - Example applications (test changes here)
103- `e2e/` - End-to-end tests (requires Playwright)
104- `docs/router/`, `docs/start/` - Documentation with React/Solid subdirectories
105​
106**Dependencies:** Uses workspace protocol (`workspace:*`) - core β†’ framework β†’ start packages
107​
108## Common development tasks
109​
110**Adding new routes:**
111​
112- Use file-based routing in `src/routes/` directories
113- Or use code-based routing with route definitions
114- Run route generation with CLI tools
115​
116**Testing changes:**
117​
118- Build packages: `pnpm build` or `pnpm dev` (watch mode)
119- Run example apps to test functionality
120- Use devtools for debugging router state
121​
122**Documentation updates:**
123​
124- Update relevant docs in `docs/` directory
125- Ensure examples reflect documentation changes
126- Test documentation links and references
127- Use relative links to `docs/` folder format
128​
129## Framework-specific notes
130​
131**React:**
132​
133- Uses React Router components and hooks
134- Supports React Server Components (RSC)
135- Examples include React Query integration
136- Package: `@tanstack/react-router`
137​
138**Solid:**
139​
140- Uses Solid Router components and primitives
141- Supports Solid Start for full-stack applications
142- Examples include Solid Query integration
143- Package: `@tanstack/solid-router`
144​
145## Environment requirements
146​
147- **Node.js** - Required for development
148- **pnpm** - Package manager (required for workspace features)
149- **Playwright** - Required for e2e tests (`pnpm exec playwright install`)
150​
151## Key architecture patterns
152​
153- **Type Safety**: Extensive TypeScript for type-safe routing
154- **Framework Agnostic**: Core logic separated from framework bindings
155- **Plugin Architecture**: Universal bundler plugins using unplugin
156- **File-based Routing**: Support for both code-based and file-based routing
157- **Search Params**: First-class support for type-safe search parameters
158​
159## Development workflow
160​
1611. **Setup**: `pnpm install` and `pnpm exec playwright install`
1622. **Build**: `pnpm build:all` or `pnpm dev` for watch mode
1633. **Test**: Make changes and run relevant tests (use nx for targeted testing)
1644. **Examples**: Navigate to examples and run `pnpm dev` to test changes
1655. **Quality**: Run `pnpm test:eslint`, `pnpm test:types`, `pnpm test:unit` before committing
166​
167## References
168​
169- **Documentation**: https://tanstack.com/router
170- **GitHub**: https://github.com/TanStack/router
171- **Discord Community**: https://discord.com/invite/WrRKjPJ