react-vite
Skill2 starsChanged 5 months agoMITView on GitHub
Conventions, pitfalls, and canonical patterns for a React + Vite SPA. Invoke when editing files under a project whose atlas detected `vite.config.{js,ts,mjs}` + React, or when the user explicitly asks for React+Vite advice. Covers component patterns, state-management decisions, Vitest+RTL+Playwright testing, build optimization, and the top hooks pitfalls.
- Reads credentials
In this repository60 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- analyzeSkill
- animation-disciplineSkill
- api-versioningSkill
- autopilotSkill
- browser-e2eSkill
- characterizeSkill
- clarifySkill
- codemodSkill
- constitution-compactSkill
- constitutionSkill
- context-budgetSkill
- creative-webSkill
- db-migrationSkill
- debugSkill
- detect-stackSkill
- dispatch-criteriaSkill
- dreamSkill
- experimentSkill
- fastapiSkill
- flag-cleanupSkill
- flag-rolloutSkill
- flask-realtimeSkill
- framework-detectorSkill
- front-end-designSkill
- grill-meSkill
- handoffSkill
- image-generationSkill
- implementSkill
- initiativeSkill
- instinctSkill
- loopSkill
- nextjsSkill
- observabilitySkill
- okr-alignSkill
- parallel-swarmSkill
- pivotSkill
- planSkill
- pr-bodySkill
- prime-disciplineSkill
- prod-observabilitySkill
- react-nodeSkill
- release-trainSkill
- researchSkill
- reviewSkill
- security-guardSkill
- self-healSkill
- shipSkill
- skill-creatorSkill
- specifySkill
- tailwind-disciplineSkill
- tasksSkill
- tdd-loopSkill
- token-budgetSkill
- typographySkill
- verify-loopSkill
- verifySkill
- wip-checkpointSkill
- <kebab-case-skill-name>Skill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Vite as the only bundler: Don't bolt Webpack/Rollup on top.
- Very specific: line 24
useEffectis an escape hatch, not a default: If you're using it for derived state, transformation, or fetching — you're holding it wrong.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
React + Vite
When to invoke
- Atlas
frameworks.web == "Vite-React"(see.claude/skills/detect-stack/SKILL.md). - Files match
vite.config.*,src/**/*.tsx,index.htmlat repo root. - User says "React app", "Vite project", or pastes a
vite.config.ts.
Key conventions
- Vite as the only bundler. Don't bolt Webpack/Rollup on top. Use
import.meta.env(notprocess.env) and prefix env varsVITE_*. - File-based but explicit routing. Pick one router (
react-router-domv6 or@tanstack/router) and stick to it. No mixing. - State ladder (start low, climb only on evidence):
useState/useReducerfor local- URL +
useSearchParamsfor shareable - React Query (
@tanstack/react-query) for server state — neveruseEffect+fetch - Zustand for cross-cutting client state (auth, theme, toasts). Prefer Zustand over Redux Toolkit for new projects unless time-travel debugging is required. Jotai if your model is atom-graph-shaped.
- Component shape. Function components only. Composition over inheritance. No
React.FC(cuts offchildrentyping). Co-locateComponent/{Component.tsx, Component.test.tsx, Component.module.css, index.ts}. useEffectis an escape hatch, not a default. If you're using it for derived state, transformation, or fetching — you're holding it wrong. Read https://react.dev/learn/you-might-not-need-an-effect.- Tests: Vitest + Testing Library + Playwright. Vitest unit, RTL component, Playwright user journey. No Enzyme. No
act()warnings ignored. - Build optimization on by default. Vite tree-shakes ESM automatically. Use
React.lazy+Suspensefor routes;manualChunksonly when you've measured. - TypeScript strict.
strict: true,noUncheckedIndexedAccess: true. Usesatisfiesfor config objects.
Canonical structure
src/
main.tsx # ReactDOM.createRoot + <App />
App.tsx # router + providers
routes/ # one file per route
index.tsx
dashboard.tsx
components/ # shared, presentational
Button/Button.tsx
features/ # feature folders (vertical slice)
auth/{api,hooks,components,types}
todos/{api,hooks,components,types}
lib/ # framework-agnostic helpers
hooks/ # cross-feature custom hooks
styles/tokens.ts # design tokens (see rules/frontend.md)
test/setup.ts # vitest setup, jest-dom matchers
vite.config.ts
vitest.config.ts
playwright.config.tsCommon pitfalls
- Stale closures in event handlers.
useEffect(() => { socket.on('msg', () => setX(x+1)) }, [])—xis frozen. Fix with functional updatersetX(p => p+1)or includexin deps. - Setting state after unmount. Async fetch resolving on an unmounted component. Use
AbortControllerin the effect cleanup or migrate to React Query (handles it). useEffectdependency lies. Exhaustive-deps is not optional — installeslint-plugin-react-hooksand treat warnings as errors.- Re-render storms from new object/array identity.
<Child config={{a:1}} />makes a new object every render. Hoist oruseMemo. - Mixing Vite env with
process.env. Vite injectsimport.meta.envat build.process.envis undefined → silentundefined. Wrap in a typed module:src/lib/env.tsreadingimport.meta.env.VITE_*with Zod.
References
- Vite: https://vitejs.dev
- React (you might not need useEffect): https://react.dev/learn/you-might-not-need-an-effect
- React Query: https://tanstack.com/query/latest
- Zustand: https://github.com/pmndrs/zustand
- Vitest: https://vitest.dev
- Testing Library: https://testing-library.com/docs/react-testing-library/intro/
Hello world (TDD)
// src/features/counter/Counter.test.tsx
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Counter } from './Counter'
test('increments on click', async () => {
render(<Counter />)
await userEvent.click(screen.getByRole('button', { name: /increment/i }))
expect(screen.getByText(/count: 1/i)).toBeInTheDocument()
})
// src/features/counter/Counter.tsx
import { useState } from 'react'
export function Counter() {
const [c, setC] = useState(0)
return <button onClick={() => setC(p => p + 1)}>Increment — count: {c}</button>
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

