From 5e67cbcfbba158d846bc90ada6db95fd67adec91 Mon Sep 17 00:00:00 2001 From: Paul O'Reilly Date: Thu, 2 Jul 2026 14:48:40 +1200 Subject: [PATCH] feat: add React + Vite dashboard best practices topic Cross-project reference covering React 19, Vite, Tailwind v4, shadcn/ui, TanStack Query/Table, react-hook-form + Zod, OIDC auth, Vitest + Testing Library + MSW, and 16 other dashboard patterns. --- BESTPRACTICES.md | 1 + react-vite-dashboard.md | 489 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 490 insertions(+) create mode 100644 react-vite-dashboard.md diff --git a/BESTPRACTICES.md b/BESTPRACTICES.md index 1c43631..7908ef8 100644 --- a/BESTPRACTICES.md +++ b/BESTPRACTICES.md @@ -32,3 +32,4 @@ Generalised best practices extracted from real project work via the `/distill-be - [AI Parallel Agents](ai-parallel-agents.md) — Parallel agent orchestration: multi-facet research dispatch, file contention, WebFetch limits, narrow reads, dataset-wide audits - [Python Patterns](python-patterns.md) — Non-reentrant Lock deadlocks, Pydantic v2 extra='ignore' silent drops, subprocess routing callables for mocking, model_validator for cross-field validation - [Mechanical Test Generation](mechanical-test-generation.md) — Spec properties that enable automated test writing: module layout tables, integration boundary marking, explicit library semantics, concrete interfaces over "implementation detail", error messages as test data, pattern tables as parametric matrices, pre-dispatch testability review +- [React + Vite Dashboard](react-vite-dashboard.md) — React 19 + Vite + Tailwind v4 + shadcn/ui dashboard patterns: component architecture (compound/slot/CVA), TanStack Query v5 (queryOptions, SSE integration, cache invalidation), TanStack Table v8 (server-side processing), react-hook-form + Zod, React Router 7 (layout routes, URL state), OIDC auth, Vitest + Testing Library + MSW, accessibility, performance (React Compiler), error boundaries diff --git a/react-vite-dashboard.md b/react-vite-dashboard.md new file mode 100644 index 0000000..23d54fe --- /dev/null +++ b/react-vite-dashboard.md @@ -0,0 +1,489 @@ +# React + Vite Dashboard Development + +Best practices for building admin/operations dashboards with React 19, Vite, Tailwind CSS v4, shadcn/ui, TanStack Query/Table, and Vitest. Distilled from community consensus and official docs (2025-2026). + +## Stack Baseline + +| Layer | Tool | Notes | +|---|---|---| +| Framework | React 19 + TypeScript | ref-as-prop, useActionState, useOptimistic, React Compiler 1.0 | +| Build | Vite + @vitejs/plugin-react | `moduleResolution: "bundler"` in tsconfig | +| Styling | Tailwind CSS v4 (CSS-first) | `@import "tailwindcss"`, `@theme` directive, no JS config | +| Components | shadcn/ui (new-york) + Radix | CVA variants, `cn()` utility, `asChild` pattern | +| Data fetching | TanStack Query v5 | `queryOptions` factories, `useSuspenseQuery` | +| Tables | TanStack Table v8 | `createColumnHelper`, server-side processing | +| Forms | react-hook-form + Zod | `zodResolver`, discriminated unions for conditional fields | +| Routing | React Router 7 | Framework or Data mode, nested layout routes | +| Auth | oidc-client-ts + react-oidc-context | PKCE + refresh tokens, `automaticSilentRenew` | +| Testing | Vitest + Testing Library + MSW v2 | happy-dom default, `userEvent.setup()` | +| Icons | lucide-react | Tree-shakeable, consistent sizing | + +## 1. Component Architecture + +### Compound components for complex UI + +Root component owns shared state via Context; child subcomponents read it. Mirrors native HTML semantics (`