react-spa-performance
БесплатноБез исполняемых скриптовНе проверенReact 19 + Vite 7 SPA performance optimization guide. Apply when writing, reviewing, or refactoring React components, routes, data fetching, bundle config, or…
от carrotwaxr★ 41 звезда на GitHubОб этом скилле
React SPA Performance (Vite + React 19)
Dense performance reference for React 19 + Vite 7 SPAs. No SSR. No Next.js.
Target projects:
- peek-stash-browser
client/— React 19, Vite 7, Tailwind v3, Video.js, React Router v7 declarative, React Compiler - stash-sense-trainer
web/— React 19, Vite 7, Tailwind v4, TanStack Query v5, React Router v7
1. Vite Build Optimization
manualChunks — group by update frequency, only node_modules:
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
'query-vendor': ['@tanstack/react-query'],
'video-vendor': ['video.js'], // isolate heavy libs used on few routes
},
},
}
Keep chunks under 200KB gzipped. Isolate heavy libs (video.js, recharts) so they load on demand.
optimizeDeps — pre-bundle CJS deps for faster dev startup:
optimizeDeps: {
include: ['react', 'react-dom', 'video.js'], // CJS libs benefit most
exclude: ['local-linked-packages'],
}
CSS code splitting — build.cssCodeSplit: true (default). Each lazy route gets its own CSS chunk automatically.
Asset inlining — build.assetsInlineLimit: 4096 (default 4KB). Raise to 8192 for many small icons.
Build target — build.target: 'es2022' unless supporting older browsers. Smaller output, no polyfills.
Tree shaking — rollupOptions.treeshake.moduleSideEffects: false (assume modules pure). Override per-module if needed.
Minification — esbuild is 10-100x faster than terser. Use terser only when the extra 1-3% matters:
build: { minify: 'terser', terserOptions: { compress: { drop_console: true, drop_debugger: true } } }
2. Code Splitting & Lazy Loading
Route-level splitting — every page component via React.lazy:
const Scenes = lazy(() => import('./pages/Scenes'));
// Single Suspense wrapping Routes for route transitions
<Suspense fallback={<PageSkeleton />}><Routes>...</Routes></Suspense>
Never lazy-load the shell/layout. Add nested <Suspense> for heavy sub-components within pages.
Dynamic imports for heavy libs — non-component imports:
async function exportData() {
const { exportToCsv } = await import('./utils/export');
exportToCsv(data);
}
Preload on hover/focus for perceived instant navigation:
const preload = () => { void import('./pages/Scenes'); };
<Link to="/scenes" onMouseEnter={preload} onFocus={preload}>Scenes</Link>
Barrel file avoidance — CRITICAL (200-800ms import cost):
// BAD: import { Check, X } from 'lucide-react';
// GOOD:
import Check from 'lucide-react/dist/esm/icons/check';
Affected: lucide-react, react-icons, @radix-ui/*, lodash, date-fns. For your own code: import from specific files, not components/index.js.
3. Re-render Prevention
React.memo — use when: component receives objects/arrays + parent re-renders frequently, or renders large subtree. Skip when: cheap component, primitive props, or React Compiler is enabled.
React 19 Compiler — when babel-plugin-react-compiler is active (peek-stash-browser), the compiler auto-memoizes components, hooks, and JSX. Remove manual memo(), useMemo, useCallback unless they serve a semantic purpose. Without compiler: apply manual memoization.
Hoist default non-primitive props:
const EMPTY = []; // outside component
<TagList tags={EMPTY} /> // stable reference, doesn't break memo
Derived state over useEffect chains — never setState in effect to transform props:
// BAD: useEffect(() => setFull(first + ' ' + last), [first, last]);
// GOOD: const fullName = first + ' ' + last;
// GOOD (expensive): const sorted = useMemo(() => items.toSorted(compare), [items]);
Don't wrap simple primitives in useMemo — hook overhead > computation cost.
Functional setState for stable callbacks:
// BAD: useCallback(() => setCount(count + 1), [count]);
// GOOD: useCallback(() => setCount(c => c + 1), []);
startTransition for non-urgent updates (filtering lists, tab switches, sorting):
const [isPending, startTransition] = useTransition();
startTransition(() => onFilter(value)); // doesn't block typing
Lifting/pushing state — push state down to the child that owns it. Lift only to nearest common ancestor. Never store server data in React state when TanStack Query handles it.
4. Context Performance
Split state vs dispatch — components calling only dispatch never re-render on state changes:
const StateCtx = createContext();
const DispatchCtx = createContext();
// Provide dispatch in outer, state in inner
Context vs props vs TanStack Query:
| Need | Solution |
|---|---|
| Server data | TanStack Query (never context) |
| Auth/theme/locale (rare changes) | Context |
| 1-2 levels of props | Props directly |
| Frequent complex state | useReducer + split context, or Zustand |
**Avoid provi
Установить react-spa-performance в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл react-spa-performance?
React 19 + Vite 7 SPA performance optimization guide. Apply when writing, reviewing, or refactoring React components, routes, data fetching, bundle config, or performance in any Vite SPA project. Covers build optimization, code splitting, re-render prevention, context design, virtualization, media loading, bundle analysis, TanStack Query, CSS, and dev performance.
Как установить скилл react-spa-performance?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл react-spa-performance запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic