agentleFS
louisbrulenaudetlouisbrulenaudet/monorepo-template/.cursor/rules/frontend/react.mdc

monorepo-template / frontend

Cursor rule18 starsChanged 59 days agoApache-2.0View on GitHub

React 19 SPA - client-only, layout and #/* imports, no fetch in useEffect, Compiler memo policy, providers, splitting, React Doctor.

  • Reads credentials

The file

We split this react.mdc into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 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.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never define a component (or a memo / lazy wrapper) inside another component's body.

    line 19
  2. Very specific:

    Keep import() statically analyzable: literal paths, or a partially dynamic path that starts with ./ / ../, ends with a file extension, and …

    line 33
  3. Very specific:

    Import large libraries from their deep path, not a barrel, so production tree-shaking drops unused exports (optimizeDeps only tunes the dev …

    line 34
  4. Very specific:

    After React changes, run pnpm react-doctor:changed and fix what it reports before calling the task done (deep workflow: skill react-doctor.

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
react.mdc
---
description: "React 19 SPA - client-only, layout and #/* imports, no fetch in useEffect, Compiler memo policy, providers, splitting, React Doctor."
alwaysApply: false
globs: apps/front-*/src/**/*.{ts,tsx},apps/front-*/index.html
---

# React SPA (React 19 + Vite)

`front-*` apps are client-only Vite SPAs: no SSR, React Server Components, or `"use server"`; ignore React guidance framed around those. Targeted performance audit: skill `vercel-react-best-practices` (browser/client guidance only).

## Layout

- Screens live in `src/pages/`, thin route shells and their `*.lazy.tsx` entries in `src/routes/` ([tanstack-router.mdc](tanstack-router.mdc)); shared UI in `src/components/` (primitives in `src/components/ui/`); non-render logic in `src/hooks/`, `src/services/`, `src/utils/`; frontend-only value sets in `src/enums/`; runtime config in `src/config/`. HTTP calls pair with their `queryOptions` in `src/services/worker-api/<feature>.ts` + `<feature>-query-options.ts`.
- Colocate feature code (route + its queries + its components) over deep global folders.
- In-app absolute imports use the `package.json` `"imports"` map (`#/*` → `./src/*`, e.g. `#/components/ui/Button`) - never an `@/` alias, `resolve.alias`, or `compilerOptions.paths`.

## Components and hooks

- Never define a component (or a `memo` / `lazy` wrapper) inside another component's body; hoist it to module scope.
- **Never fetch in `useEffect`** or mirror query data into local state: server state is TanStack Query ([tanstack-query.mdc](tanstack-query.mdc)), and `react-doctor/no-fetch-in-effect` is a lint error. Derive during render rather than syncing props/state in `useEffect`; effects are only for external sync and clean up on unmount.
- React Compiler is on: do not default to `useMemo` / `useCallback` / `memo`; they are an escape hatch.
- `useTransition` / `startTransition` / `useDeferredValue` for non-urgent or expensive UI work.
- List keys use stable identity (`item.id`), never the index when order can change.
- `ref` is a normal prop (no new `forwardRef`). `use()` only with a stable cached promise under `<Suspense>`, never `use(fetch(...))` created during render.
- Hook rules (`react/rules-of-hooks`, `react/exhaustive-deps`) and `jsx-a11y` (partial a11y coverage) are oxlint rules; never add an ESLint / `eslint-plugin-react-hooks` toolchain.

## Entry, providers, bundle

- Providers compose once at the root, outermost first: `<QueryClientProvider>` → `<RouterProvider>`, with a top-level error boundary, route-level `<Suspense>` / pending components, error boundaries at tree and lazy-route edges, and route errors through the router's `errorComponent`.
- One module-singleton `QueryClient` in `src/config/query-client.ts` (never `new QueryClient()` in a component) and one `router` at module scope, with `queryClient` in its context today; pass further runtime values through `<RouterProvider context={...}>` when they exist. Auth, when added, belongs in route `beforeLoad` / context; never invent an auth field the app does not define.
- Devtools (`ReactQueryDevtools`, router devtools) mount dev-only behind `import.meta.env.DEV`, so production tree-shakes them.
- Routes split through the router's `autoCodeSplitting`; `React.lazy` + `<Suspense>` for heavy, rarely used components (editors, charts); defer non-critical third-party libraries (analytics) until after first paint; preload heavy chunks on intent (`onMouseEnter` / `onFocus` → `void import("./heavy")`).
- Keep `import()` statically analyzable: literal paths, or a partially dynamic path that starts with `./` / `../`, ends with a file extension, and varies one path segment (`` import(`./locales/${lang}.json`) ``); a fully dynamic `import(pathVariable)` cannot be chunked.
- Import large libraries from their deep path, not a barrel, so production tree-shaking drops unused exports (`optimizeDeps` only tunes the dev pre-bundler).
- Client env is `VITE_*` only and is inlined into the public bundle: never a secret. Read it through `src/config/env.ts` with a fallback, not scattered `import.meta.env.X` reads. Exception: `src/config/sentry.ts` reads `VITE_SENTRY_DSN` literally, so an unset DSN drops the SDK from the build.

## React Doctor

- After React changes, run `pnpm react-doctor:changed` and fix what it reports before calling the task done (deep workflow: skill `react-doctor`; config: [lint-config.mdc](../quality/lint-config.mdc)).
- Suppress inline only when justified: `// react-doctor-disable-next-line react-doctor/<rule>`. Never delete a correctness diagnostic to go green; run `pnpm react-doctor why <file>:<line>` when unclear.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.