ganbatte-os 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +46 -0
- package/CLAUDE.md +31 -0
- package/GEMINI.md +17 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/agents/profiles/architect.md +13 -0
- package/agents/profiles/dev.md +13 -0
- package/agents/profiles/devops.md +12 -0
- package/agents/profiles/ganbatte-os-master.md +444 -0
- package/agents/profiles/index.json +14 -0
- package/agents/profiles/po.md +7 -0
- package/agents/profiles/qa.md +456 -0
- package/agents/profiles/sm.md +7 -0
- package/agents/profiles/squad-creator.md +7 -0
- package/agents/profiles/ux-design-expert.md +14 -0
- package/config.json +15 -0
- package/docs/curation.md +60 -0
- package/docs/gos_installation_guide.md +114 -0
- package/docs/ide-compatibility.md +20 -0
- package/docs/plan/plan-git-operations.md +51 -0
- package/docs/plan-distribuicao-publica.md +360 -0
- package/docs/stacks/stack-git-operations.md +154 -0
- package/docs/toolchain-map.md +18 -0
- package/integrations/README.md +42 -0
- package/integrations/antigravity/README.md +29 -0
- package/integrations/antigravity/command-map.json +29 -0
- package/integrations/claude/README.md +35 -0
- package/integrations/claude/agent-map.json +46 -0
- package/integrations/claude/command-map.json +32 -0
- package/integrations/claude/litellm-proxy.md +93 -0
- package/integrations/claude/mcp-specifics.md +121 -0
- package/integrations/codex/README.md +29 -0
- package/integrations/codex/command-map.json +29 -0
- package/integrations/cursor/README.md +8 -0
- package/integrations/cursor/command-map.json +11 -0
- package/integrations/gemini/README.md +13 -0
- package/integrations/gemini/command-map.json +11 -0
- package/integrations/kilo-code/README.md +7 -0
- package/integrations/kilo-code/command-map.json +11 -0
- package/integrations/opencode/README.md +91 -0
- package/integrations/opencode/command-map.json +46 -0
- package/integrations/registry.json +20 -0
- package/manifests/g-os-runtime-manifest.json +39 -0
- package/manifests/gos-install-manifest.json +46 -0
- package/opencode.json +7 -0
- package/package.json +51 -0
- package/playbooks/feature-development-playbook.md +239 -0
- package/playbooks/sprint-planner-playbook.md +127 -0
- package/playbooks/squad-pipeline-runner.md +196 -0
- package/playbooks/ssh-multi-account-setup.md +185 -0
- package/prompts/01-search.md +18 -0
- package/prompts/02-spec.md +19 -0
- package/prompts/03-tasks.md +15 -0
- package/prompts/04-code.md +10 -0
- package/prompts/05-reviews.md +11 -0
- package/rules/plan-mode.md +60 -0
- package/scripts/cli/gos-cli.js +679 -0
- package/scripts/hooks/pre-commit-validate.js +201 -0
- package/scripts/integrations/check-ide-compat.js +44 -0
- package/scripts/integrations/setup-ide-adapters.js +87 -0
- package/scripts/tools/clickup-preprocess.js +218 -0
- package/scripts/tools/clickup.js +1058 -0
- package/skills/agent-teams/SKILL.md +78 -0
- package/skills/agent-teams/presets/team-all.yaml +14 -0
- package/skills/agent-teams/presets/team-fullstack.yaml +17 -0
- package/skills/agent-teams/presets/team-ide-minimal.yaml +9 -0
- package/skills/agent-teams/presets/team-no-ui.yaml +12 -0
- package/skills/agent-teams/presets/team-qa-focused.yaml +83 -0
- package/skills/clickup/SKILL.md +151 -0
- package/skills/component-dedup/SKILL.md +101 -0
- package/skills/design-to-code/SKILL.md +255 -0
- package/skills/figma-implement-design/SKILL.md +227 -0
- package/skills/figma-make-analyzer/SKILL.md +140 -0
- package/skills/frontend-dev/SKILL.md +271 -0
- package/skills/git-ssh-setup/SKILL.md +164 -0
- package/skills/interface-design/SKILL.md +350 -0
- package/skills/interface-design/references/audit.md +76 -0
- package/skills/interface-design/references/craft-examples.md +134 -0
- package/skills/interface-design/references/critique.md +92 -0
- package/skills/interface-design/references/extract.md +92 -0
- package/skills/interface-design/references/principles.md +348 -0
- package/skills/interface-design/references/templates/system-precision.md +73 -0
- package/skills/interface-design/references/templates/system-warmth.md +67 -0
- package/skills/interface-design/references/validation.md +137 -0
- package/skills/make-code-triage/SKILL.md +135 -0
- package/skills/make-version-diff/SKILL.md +87 -0
- package/skills/plan-to-tasks/SKILL.md +136 -0
- package/skills/react-best-practices/AGENTS.md +2975 -0
- package/skills/react-best-practices/SKILL.md +151 -0
- package/skills/react-best-practices/metadata.json +15 -0
- package/skills/react-best-practices/rules/_sections.md +46 -0
- package/skills/react-best-practices/rules/_template.md +28 -0
- package/skills/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skills/react-best-practices/rules/advanced-init-once.md +42 -0
- package/skills/react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skills/react-best-practices/rules/async-api-routes.md +38 -0
- package/skills/react-best-practices/rules/async-defer-await.md +80 -0
- package/skills/react-best-practices/rules/async-dependencies.md +51 -0
- package/skills/react-best-practices/rules/async-parallel.md +28 -0
- package/skills/react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skills/react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/skills/react-best-practices/rules/bundle-conditional.md +31 -0
- package/skills/react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/skills/react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/skills/react-best-practices/rules/bundle-preload.md +50 -0
- package/skills/react-best-practices/rules/client-event-listeners.md +74 -0
- package/skills/react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/skills/react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skills/react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skills/react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/skills/react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skills/react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skills/react-best-practices/rules/js-cache-storage.md +70 -0
- package/skills/react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skills/react-best-practices/rules/js-early-exit.md +50 -0
- package/skills/react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skills/react-best-practices/rules/js-index-maps.md +37 -0
- package/skills/react-best-practices/rules/js-length-check-first.md +49 -0
- package/skills/react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skills/react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skills/react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skills/react-best-practices/rules/rendering-activity.md +26 -0
- package/skills/react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/skills/react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/skills/react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skills/react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/skills/react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/skills/react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/skills/react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skills/react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skills/react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skills/react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skills/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skills/react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skills/react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/skills/react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/skills/react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/skills/react-best-practices/rules/rerender-memo.md +44 -0
- package/skills/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skills/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skills/react-best-practices/rules/rerender-transitions.md +40 -0
- package/skills/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skills/react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skills/react-best-practices/rules/server-auth-actions.md +96 -0
- package/skills/react-best-practices/rules/server-cache-lru.md +41 -0
- package/skills/react-best-practices/rules/server-cache-react.md +76 -0
- package/skills/react-best-practices/rules/server-dedup-props.md +65 -0
- package/skills/react-best-practices/rules/server-hoist-static-io.md +142 -0
- package/skills/react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skills/react-best-practices/rules/server-serialization.md +38 -0
- package/skills/react-doctor/SKILL.md +74 -0
- package/skills/registry.json +21 -0
- package/skills/sprint-planner/SKILL.md +434 -0
- package/squads/design-delivery/README.md +10 -0
- package/squads/design-delivery/squad.yaml +30 -0
- package/squads/design-delivery/workflows/wf-design-delivery.yaml +27 -0
- package/squads/design-squad/README.md +31 -0
- package/squads/design-squad/agents/brad-frost.md +185 -0
- package/squads/design-squad/agents/dan-mall.md +178 -0
- package/squads/design-squad/agents/dave-malouf.md +198 -0
- package/squads/design-squad/agents/design-chief.md +109 -0
- package/squads/design-squad/agents/design-system-architect.md +109 -0
- package/squads/design-squad/agents/ui-engineer.md +102 -0
- package/squads/design-squad/agents/ux-designer.md +105 -0
- package/squads/design-squad/agents/visual-generator.md +108 -0
- package/squads/design-squad/checklists/output-quality.md +76 -0
- package/squads/design-squad/config/config.yaml +65 -0
- package/squads/design-squad/data/design-patterns-catalog.yaml +276 -0
- package/squads/design-squad/data/routing-catalog.yaml +95 -0
- package/squads/design-squad/squad.yaml +88 -0
- package/squads/design-squad/tasks/audit-design.md +174 -0
- package/squads/design-squad/tasks/create-component-spec.md +185 -0
- package/squads/design-squad/tasks/create-design-system.md +179 -0
- package/squads/design-squad/tasks/design-ux-flow.md +184 -0
- package/squads/design-squad/tasks/diagnose.md +138 -0
- package/squads/design-squad/tasks/generate-handoff.md +186 -0
- package/squads/design-squad/tasks/review.md +133 -0
- package/squads/design-squad/tasks/setup-design-ops.md +177 -0
- package/squads/design-squad/workflows/wf-design-system-creation.yaml +131 -0
- package/squads/design-squad/workflows/wf-feature-design.yaml +114 -0
- package/squads/git-operations/README.md +30 -0
- package/squads/git-operations/squad.yaml +27 -0
- package/squads/git-operations/workflows/wf-safe-commit.yaml +27 -0
- package/squads/git-operations/workflows/wf-ssh-setup.yaml +27 -0
- package/squads/sprint-planning/agents/sprint-chief.md +47 -0
- package/squads/sprint-planning/agents/sprint-planner-agent.md +43 -0
- package/squads/sprint-planning/agents/sprint-tracker.md +43 -0
- package/squads/sprint-planning/agents/task-importer.md +44 -0
- package/squads/sprint-planning/checklists/sprint-readiness.md +27 -0
- package/squads/sprint-planning/config/config.yaml +65 -0
- package/squads/sprint-planning/data/clickup-field-mapping.yaml +94 -0
- package/squads/sprint-planning/squad.yaml +52 -0
- package/squads/sprint-planning/tasks/close-sprint.md +43 -0
- package/squads/sprint-planning/tasks/create-sprint.md +42 -0
- package/squads/sprint-planning/tasks/import-tasks.md +39 -0
- package/squads/sprint-planning/tasks/sync-status.md +31 -0
- package/squads/sprint-planning/workflows/wf-sprint-creation.yaml +59 -0
- package/squads/sprint-planning/workflows/wf-sprint-sync.yaml +35 -0
- package/templates/adr-tmpl.yaml +76 -0
- package/templates/sprint-clickup.template.md +80 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-best-practices
|
|
3
|
+
description: >
|
|
4
|
+
React and Next.js performance optimization guidelines from Vercel Engineering.
|
|
5
|
+
Use when writing, reviewing, or refactoring React/Next.js code to ensure optimal
|
|
6
|
+
performance patterns. Triggers on tasks involving React components, Next.js pages,
|
|
7
|
+
data fetching, bundle optimization, or performance improvements.
|
|
8
|
+
license: MIT
|
|
9
|
+
use-when:
|
|
10
|
+
- escrever novos componentes React ou paginas Next.js
|
|
11
|
+
- revisar ou refatorar codigo React/Next.js para performance
|
|
12
|
+
- otimizar bundle size, data fetching ou re-renders
|
|
13
|
+
- implementar server components, Suspense ou streaming
|
|
14
|
+
do-not-use-for:
|
|
15
|
+
- arquitetura de composicao de componentes — use composition-patterns
|
|
16
|
+
- componentes React Native — use react-native-skills
|
|
17
|
+
- deploy para Vercel — use deploy-to-vercel
|
|
18
|
+
metadata:
|
|
19
|
+
author: vercel
|
|
20
|
+
version: "1.0.0"
|
|
21
|
+
category: document-asset
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# Vercel React Best Practices
|
|
25
|
+
|
|
26
|
+
Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 58 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
|
|
27
|
+
|
|
28
|
+
## When to Apply
|
|
29
|
+
|
|
30
|
+
Reference these guidelines when:
|
|
31
|
+
- Writing new React components or Next.js pages
|
|
32
|
+
- Implementing data fetching (client or server-side)
|
|
33
|
+
- Reviewing code for performance issues
|
|
34
|
+
- Refactoring existing React/Next.js code
|
|
35
|
+
- Optimizing bundle size or load times
|
|
36
|
+
|
|
37
|
+
## Rule Categories by Priority
|
|
38
|
+
|
|
39
|
+
| Priority | Category | Impact | Prefix |
|
|
40
|
+
|----------|----------|--------|--------|
|
|
41
|
+
| 1 | Eliminating Waterfalls | CRITICAL | `async-` |
|
|
42
|
+
| 2 | Bundle Size Optimization | CRITICAL | `bundle-` |
|
|
43
|
+
| 3 | Server-Side Performance | HIGH | `server-` |
|
|
44
|
+
| 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |
|
|
45
|
+
| 5 | Re-render Optimization | MEDIUM | `rerender-` |
|
|
46
|
+
| 6 | Rendering Performance | MEDIUM | `rendering-` |
|
|
47
|
+
| 7 | JavaScript Performance | LOW-MEDIUM | `js-` |
|
|
48
|
+
| 8 | Advanced Patterns | LOW | `advanced-` |
|
|
49
|
+
|
|
50
|
+
## Quick Reference
|
|
51
|
+
|
|
52
|
+
### 1. Eliminating Waterfalls (CRITICAL)
|
|
53
|
+
|
|
54
|
+
- `async-defer-await` - Move await into branches where actually used
|
|
55
|
+
- `async-parallel` - Use Promise.all() for independent operations
|
|
56
|
+
- `async-dependencies` - Use better-all for partial dependencies
|
|
57
|
+
- `async-api-routes` - Start promises early, await late in API routes
|
|
58
|
+
- `async-suspense-boundaries` - Use Suspense to stream content
|
|
59
|
+
|
|
60
|
+
### 2. Bundle Size Optimization (CRITICAL)
|
|
61
|
+
|
|
62
|
+
- `bundle-barrel-imports` - Import directly, avoid barrel files
|
|
63
|
+
- `bundle-dynamic-imports` - Use next/dynamic for heavy components
|
|
64
|
+
- `bundle-defer-third-party` - Load analytics/logging after hydration
|
|
65
|
+
- `bundle-conditional` - Load modules only when feature is activated
|
|
66
|
+
- `bundle-preload` - Preload on hover/focus for perceived speed
|
|
67
|
+
|
|
68
|
+
### 3. Server-Side Performance (HIGH)
|
|
69
|
+
|
|
70
|
+
- `server-auth-actions` - Authenticate server actions like API routes
|
|
71
|
+
- `server-cache-react` - Use React.cache() for per-request deduplication
|
|
72
|
+
- `server-cache-lru` - Use LRU cache for cross-request caching
|
|
73
|
+
- `server-dedup-props` - Avoid duplicate serialization in RSC props
|
|
74
|
+
- `server-hoist-static-io` - Hoist static I/O (fonts, logos) to module level
|
|
75
|
+
- `server-serialization` - Minimize data passed to client components
|
|
76
|
+
- `server-parallel-fetching` - Restructure components to parallelize fetches
|
|
77
|
+
- `server-after-nonblocking` - Use after() for non-blocking operations
|
|
78
|
+
|
|
79
|
+
### 4. Client-Side Data Fetching (MEDIUM-HIGH)
|
|
80
|
+
|
|
81
|
+
- `client-swr-dedup` - Use SWR for automatic request deduplication
|
|
82
|
+
- `client-event-listeners` - Deduplicate global event listeners
|
|
83
|
+
- `client-passive-event-listeners` - Use passive listeners for scroll
|
|
84
|
+
- `client-localstorage-schema` - Version and minimize localStorage data
|
|
85
|
+
|
|
86
|
+
### 5. Re-render Optimization (MEDIUM)
|
|
87
|
+
|
|
88
|
+
- `rerender-defer-reads` - Don't subscribe to state only used in callbacks
|
|
89
|
+
- `rerender-memo` - Extract expensive work into memoized components
|
|
90
|
+
- `rerender-memo-with-default-value` - Hoist default non-primitive props
|
|
91
|
+
- `rerender-dependencies` - Use primitive dependencies in effects
|
|
92
|
+
- `rerender-derived-state` - Subscribe to derived booleans, not raw values
|
|
93
|
+
- `rerender-derived-state-no-effect` - Derive state during render, not effects
|
|
94
|
+
- `rerender-functional-setstate` - Use functional setState for stable callbacks
|
|
95
|
+
- `rerender-lazy-state-init` - Pass function to useState for expensive values
|
|
96
|
+
- `rerender-simple-expression-in-memo` - Avoid memo for simple primitives
|
|
97
|
+
- `rerender-move-effect-to-event` - Put interaction logic in event handlers
|
|
98
|
+
- `rerender-transitions` - Use startTransition for non-urgent updates
|
|
99
|
+
- `rerender-use-ref-transient-values` - Use refs for transient frequent values
|
|
100
|
+
|
|
101
|
+
### 6. Rendering Performance (MEDIUM)
|
|
102
|
+
|
|
103
|
+
- `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element
|
|
104
|
+
- `rendering-content-visibility` - Use content-visibility for long lists
|
|
105
|
+
- `rendering-hoist-jsx` - Extract static JSX outside components
|
|
106
|
+
- `rendering-svg-precision` - Reduce SVG coordinate precision
|
|
107
|
+
- `rendering-hydration-no-flicker` - Use inline script for client-only data
|
|
108
|
+
- `rendering-hydration-suppress-warning` - Suppress expected mismatches
|
|
109
|
+
- `rendering-activity` - Use Activity component for show/hide
|
|
110
|
+
- `rendering-conditional-render` - Use ternary, not && for conditionals
|
|
111
|
+
- `rendering-usetransition-loading` - Prefer useTransition for loading state
|
|
112
|
+
|
|
113
|
+
### 7. JavaScript Performance (LOW-MEDIUM)
|
|
114
|
+
|
|
115
|
+
- `js-batch-dom-css` - Group CSS changes via classes or cssText
|
|
116
|
+
- `js-index-maps` - Build Map for repeated lookups
|
|
117
|
+
- `js-cache-property-access` - Cache object properties in loops
|
|
118
|
+
- `js-cache-function-results` - Cache function results in module-level Map
|
|
119
|
+
- `js-cache-storage` - Cache localStorage/sessionStorage reads
|
|
120
|
+
- `js-combine-iterations` - Combine multiple filter/map into one loop
|
|
121
|
+
- `js-length-check-first` - Check array length before expensive comparison
|
|
122
|
+
- `js-early-exit` - Return early from functions
|
|
123
|
+
- `js-hoist-regexp` - Hoist RegExp creation outside loops
|
|
124
|
+
- `js-min-max-loop` - Use loop for min/max instead of sort
|
|
125
|
+
- `js-set-map-lookups` - Use Set/Map for O(1) lookups
|
|
126
|
+
- `js-tosorted-immutable` - Use toSorted() for immutability
|
|
127
|
+
|
|
128
|
+
### 8. Advanced Patterns (LOW)
|
|
129
|
+
|
|
130
|
+
- `advanced-event-handler-refs` - Store event handlers in refs
|
|
131
|
+
- `advanced-init-once` - Initialize app once per app load
|
|
132
|
+
- `advanced-use-latest` - useLatest for stable callback refs
|
|
133
|
+
|
|
134
|
+
## How to Use
|
|
135
|
+
|
|
136
|
+
Read individual rule files for detailed explanations and code examples:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
rules/async-parallel.md
|
|
140
|
+
rules/bundle-barrel-imports.md
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Each rule file contains:
|
|
144
|
+
- Brief explanation of why it matters
|
|
145
|
+
- Incorrect code example with explanation
|
|
146
|
+
- Correct code example with explanation
|
|
147
|
+
- Additional context and references
|
|
148
|
+
|
|
149
|
+
## Full Compiled Document
|
|
150
|
+
|
|
151
|
+
For the complete guide with all rules expanded: `AGENTS.md`
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"organization": "Vercel Engineering",
|
|
4
|
+
"date": "January 2026",
|
|
5
|
+
"abstract": "Comprehensive performance optimization guide for React and Next.js applications, designed for AI agents and LLMs. Contains 40+ rules across 8 categories, prioritized by impact from critical (eliminating waterfalls, reducing bundle size) to incremental (advanced patterns). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics to guide automated refactoring and code generation.",
|
|
6
|
+
"references": [
|
|
7
|
+
"https://react.dev",
|
|
8
|
+
"https://nextjs.org",
|
|
9
|
+
"https://swr.vercel.app",
|
|
10
|
+
"https://github.com/shuding/better-all",
|
|
11
|
+
"https://github.com/isaacs/node-lru-cache",
|
|
12
|
+
"https://vercel.com/blog/how-we-optimized-package-imports-in-next-js",
|
|
13
|
+
"https://vercel.com/blog/how-we-made-the-vercel-dashboard-twice-as-fast"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Sections
|
|
2
|
+
|
|
3
|
+
This file defines all sections, their ordering, impact levels, and descriptions.
|
|
4
|
+
The section ID (in parentheses) is the filename prefix used to group rules.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Eliminating Waterfalls (async)
|
|
9
|
+
|
|
10
|
+
**Impact:** CRITICAL
|
|
11
|
+
**Description:** Waterfalls are the #1 performance killer. Each sequential await adds full network latency. Eliminating them yields the largest gains.
|
|
12
|
+
|
|
13
|
+
## 2. Bundle Size Optimization (bundle)
|
|
14
|
+
|
|
15
|
+
**Impact:** CRITICAL
|
|
16
|
+
**Description:** Reducing initial bundle size improves Time to Interactive and Largest Contentful Paint.
|
|
17
|
+
|
|
18
|
+
## 3. Server-Side Performance (server)
|
|
19
|
+
|
|
20
|
+
**Impact:** HIGH
|
|
21
|
+
**Description:** Optimizing server-side rendering and data fetching eliminates server-side waterfalls and reduces response times.
|
|
22
|
+
|
|
23
|
+
## 4. Client-Side Data Fetching (client)
|
|
24
|
+
|
|
25
|
+
**Impact:** MEDIUM-HIGH
|
|
26
|
+
**Description:** Automatic deduplication and efficient data fetching patterns reduce redundant network requests.
|
|
27
|
+
|
|
28
|
+
## 5. Re-render Optimization (rerender)
|
|
29
|
+
|
|
30
|
+
**Impact:** MEDIUM
|
|
31
|
+
**Description:** Reducing unnecessary re-renders minimizes wasted computation and improves UI responsiveness.
|
|
32
|
+
|
|
33
|
+
## 6. Rendering Performance (rendering)
|
|
34
|
+
|
|
35
|
+
**Impact:** MEDIUM
|
|
36
|
+
**Description:** Optimizing the rendering process reduces the work the browser needs to do.
|
|
37
|
+
|
|
38
|
+
## 7. JavaScript Performance (js)
|
|
39
|
+
|
|
40
|
+
**Impact:** LOW-MEDIUM
|
|
41
|
+
**Description:** Micro-optimizations for hot paths can add up to meaningful improvements.
|
|
42
|
+
|
|
43
|
+
## 8. Advanced Patterns (advanced)
|
|
44
|
+
|
|
45
|
+
**Impact:** LOW
|
|
46
|
+
**Description:** Advanced patterns for specific cases that require careful implementation.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Rule Title Here
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Optional description of impact (e.g., "20-50% improvement")
|
|
5
|
+
tags: tag1, tag2
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Rule Title Here
|
|
9
|
+
|
|
10
|
+
**Impact: MEDIUM (optional impact description)**
|
|
11
|
+
|
|
12
|
+
Brief explanation of the rule and why it matters. This should be clear and concise, explaining the performance implications.
|
|
13
|
+
|
|
14
|
+
**Incorrect (description of what's wrong):**
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// Bad code example here
|
|
18
|
+
const bad = example()
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Correct (description of what's right):**
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// Good code example here
|
|
25
|
+
const good = example()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Reference: [Link to documentation or resource](https://example.com)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Store Event Handlers in Refs
|
|
3
|
+
impact: LOW
|
|
4
|
+
impactDescription: stable subscriptions
|
|
5
|
+
tags: advanced, hooks, refs, event-handlers, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Store Event Handlers in Refs
|
|
9
|
+
|
|
10
|
+
Store callbacks in refs when used in effects that shouldn't re-subscribe on callback changes.
|
|
11
|
+
|
|
12
|
+
**Incorrect (re-subscribes on every render):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function useWindowEvent(event: string, handler: (e) => void) {
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
window.addEventListener(event, handler)
|
|
18
|
+
return () => window.removeEventListener(event, handler)
|
|
19
|
+
}, [event, handler])
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Correct (stable subscription):**
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
function useWindowEvent(event: string, handler: (e) => void) {
|
|
27
|
+
const handlerRef = useRef(handler)
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
handlerRef.current = handler
|
|
30
|
+
}, [handler])
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const listener = (e) => handlerRef.current(e)
|
|
34
|
+
window.addEventListener(event, listener)
|
|
35
|
+
return () => window.removeEventListener(event, listener)
|
|
36
|
+
}, [event])
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Alternative: use `useEffectEvent` if you're on latest React:**
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { useEffectEvent } from 'react'
|
|
44
|
+
|
|
45
|
+
function useWindowEvent(event: string, handler: (e) => void) {
|
|
46
|
+
const onEvent = useEffectEvent(handler)
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
window.addEventListener(event, onEvent)
|
|
50
|
+
return () => window.removeEventListener(event, onEvent)
|
|
51
|
+
}, [event])
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`useEffectEvent` provides a cleaner API for the same pattern: it creates a stable function reference that always calls the latest version of the handler.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Initialize App Once, Not Per Mount
|
|
3
|
+
impact: LOW-MEDIUM
|
|
4
|
+
impactDescription: avoids duplicate init in development
|
|
5
|
+
tags: initialization, useEffect, app-startup, side-effects
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Initialize App Once, Not Per Mount
|
|
9
|
+
|
|
10
|
+
Do not put app-wide initialization that must run once per app load inside `useEffect([])` of a component. Components can remount and effects will re-run. Use a module-level guard or top-level init in the entry module instead.
|
|
11
|
+
|
|
12
|
+
**Incorrect (runs twice in dev, re-runs on remount):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function Comp() {
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
loadFromStorage()
|
|
18
|
+
checkAuthToken()
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
// ...
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (once per app load):**
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
let didInit = false
|
|
29
|
+
|
|
30
|
+
function Comp() {
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (didInit) return
|
|
33
|
+
didInit = true
|
|
34
|
+
loadFromStorage()
|
|
35
|
+
checkAuthToken()
|
|
36
|
+
}, [])
|
|
37
|
+
|
|
38
|
+
// ...
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Reference: [Initializing the application](https://react.dev/learn/you-might-not-need-an-effect#initializing-the-application)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useEffectEvent for Stable Callback Refs
|
|
3
|
+
impact: LOW
|
|
4
|
+
impactDescription: prevents effect re-runs
|
|
5
|
+
tags: advanced, hooks, useEffectEvent, refs, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## useEffectEvent for Stable Callback Refs
|
|
9
|
+
|
|
10
|
+
Access latest values in callbacks without adding them to dependency arrays. Prevents effect re-runs while avoiding stale closures.
|
|
11
|
+
|
|
12
|
+
**Incorrect (effect re-runs on every callback change):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function SearchInput({ onSearch }: { onSearch: (q: string) => void }) {
|
|
16
|
+
const [query, setQuery] = useState('')
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const timeout = setTimeout(() => onSearch(query), 300)
|
|
20
|
+
return () => clearTimeout(timeout)
|
|
21
|
+
}, [query, onSearch])
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (using React's useEffectEvent):**
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { useEffectEvent } from 'react';
|
|
29
|
+
|
|
30
|
+
function SearchInput({ onSearch }: { onSearch: (q: string) => void }) {
|
|
31
|
+
const [query, setQuery] = useState('')
|
|
32
|
+
const onSearchEvent = useEffectEvent(onSearch)
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const timeout = setTimeout(() => onSearchEvent(query), 300)
|
|
36
|
+
return () => clearTimeout(timeout)
|
|
37
|
+
}, [query])
|
|
38
|
+
}
|
|
39
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Prevent Waterfall Chains in API Routes
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: 2-10× improvement
|
|
5
|
+
tags: api-routes, server-actions, waterfalls, parallelization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Prevent Waterfall Chains in API Routes
|
|
9
|
+
|
|
10
|
+
In API routes and Server Actions, start independent operations immediately, even if you don't await them yet.
|
|
11
|
+
|
|
12
|
+
**Incorrect (config waits for auth, data waits for both):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
export async function GET(request: Request) {
|
|
16
|
+
const session = await auth()
|
|
17
|
+
const config = await fetchConfig()
|
|
18
|
+
const data = await fetchData(session.user.id)
|
|
19
|
+
return Response.json({ data, config })
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Correct (auth and config start immediately):**
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
export async function GET(request: Request) {
|
|
27
|
+
const sessionPromise = auth()
|
|
28
|
+
const configPromise = fetchConfig()
|
|
29
|
+
const session = await sessionPromise
|
|
30
|
+
const [config, data] = await Promise.all([
|
|
31
|
+
configPromise,
|
|
32
|
+
fetchData(session.user.id)
|
|
33
|
+
])
|
|
34
|
+
return Response.json({ data, config })
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For operations with more complex dependency chains, use `better-all` to automatically maximize parallelism (see Dependency-Based Parallelization).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Defer Await Until Needed
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: avoids blocking unused code paths
|
|
5
|
+
tags: async, await, conditional, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Defer Await Until Needed
|
|
9
|
+
|
|
10
|
+
Move `await` operations into the branches where they're actually used to avoid blocking code paths that don't need them.
|
|
11
|
+
|
|
12
|
+
**Incorrect (blocks both branches):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
async function handleRequest(userId: string, skipProcessing: boolean) {
|
|
16
|
+
const userData = await fetchUserData(userId)
|
|
17
|
+
|
|
18
|
+
if (skipProcessing) {
|
|
19
|
+
// Returns immediately but still waited for userData
|
|
20
|
+
return { skipped: true }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Only this branch uses userData
|
|
24
|
+
return processUserData(userData)
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Correct (only blocks when needed):**
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
async function handleRequest(userId: string, skipProcessing: boolean) {
|
|
32
|
+
if (skipProcessing) {
|
|
33
|
+
// Returns immediately without waiting
|
|
34
|
+
return { skipped: true }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Fetch only when needed
|
|
38
|
+
const userData = await fetchUserData(userId)
|
|
39
|
+
return processUserData(userData)
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Another example (early return optimization):**
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// Incorrect: always fetches permissions
|
|
47
|
+
async function updateResource(resourceId: string, userId: string) {
|
|
48
|
+
const permissions = await fetchPermissions(userId)
|
|
49
|
+
const resource = await getResource(resourceId)
|
|
50
|
+
|
|
51
|
+
if (!resource) {
|
|
52
|
+
return { error: 'Not found' }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!permissions.canEdit) {
|
|
56
|
+
return { error: 'Forbidden' }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return await updateResourceData(resource, permissions)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Correct: fetches only when needed
|
|
63
|
+
async function updateResource(resourceId: string, userId: string) {
|
|
64
|
+
const resource = await getResource(resourceId)
|
|
65
|
+
|
|
66
|
+
if (!resource) {
|
|
67
|
+
return { error: 'Not found' }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const permissions = await fetchPermissions(userId)
|
|
71
|
+
|
|
72
|
+
if (!permissions.canEdit) {
|
|
73
|
+
return { error: 'Forbidden' }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return await updateResourceData(resource, permissions)
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This optimization is especially valuable when the skipped branch is frequently taken, or when the deferred operation is expensive.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Dependency-Based Parallelization
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: 2-10× improvement
|
|
5
|
+
tags: async, parallelization, dependencies, better-all
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Dependency-Based Parallelization
|
|
9
|
+
|
|
10
|
+
For operations with partial dependencies, use `better-all` to maximize parallelism. It automatically starts each task at the earliest possible moment.
|
|
11
|
+
|
|
12
|
+
**Incorrect (profile waits for config unnecessarily):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const [user, config] = await Promise.all([
|
|
16
|
+
fetchUser(),
|
|
17
|
+
fetchConfig()
|
|
18
|
+
])
|
|
19
|
+
const profile = await fetchProfile(user.id)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (config and profile run in parallel):**
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { all } from 'better-all'
|
|
26
|
+
|
|
27
|
+
const { user, config, profile } = await all({
|
|
28
|
+
async user() { return fetchUser() },
|
|
29
|
+
async config() { return fetchConfig() },
|
|
30
|
+
async profile() {
|
|
31
|
+
return fetchProfile((await this.$.user).id)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Alternative without extra dependencies:**
|
|
37
|
+
|
|
38
|
+
We can also create all the promises first, and do `Promise.all()` at the end.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const userPromise = fetchUser()
|
|
42
|
+
const profilePromise = userPromise.then(user => fetchProfile(user.id))
|
|
43
|
+
|
|
44
|
+
const [user, config, profile] = await Promise.all([
|
|
45
|
+
userPromise,
|
|
46
|
+
fetchConfig(),
|
|
47
|
+
profilePromise
|
|
48
|
+
])
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Reference: [https://github.com/shuding/better-all](https://github.com/shuding/better-all)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Promise.all() for Independent Operations
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: 2-10× improvement
|
|
5
|
+
tags: async, parallelization, promises, waterfalls
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Promise.all() for Independent Operations
|
|
9
|
+
|
|
10
|
+
When async operations have no interdependencies, execute them concurrently using `Promise.all()`.
|
|
11
|
+
|
|
12
|
+
**Incorrect (sequential execution, 3 round trips):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const user = await fetchUser()
|
|
16
|
+
const posts = await fetchPosts()
|
|
17
|
+
const comments = await fetchComments()
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Correct (parallel execution, 1 round trip):**
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
const [user, posts, comments] = await Promise.all([
|
|
24
|
+
fetchUser(),
|
|
25
|
+
fetchPosts(),
|
|
26
|
+
fetchComments()
|
|
27
|
+
])
|
|
28
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Strategic Suspense Boundaries
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: faster initial paint
|
|
5
|
+
tags: async, suspense, streaming, layout-shift
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Strategic Suspense Boundaries
|
|
9
|
+
|
|
10
|
+
Instead of awaiting data in async components before returning JSX, use Suspense boundaries to show the wrapper UI faster while data loads.
|
|
11
|
+
|
|
12
|
+
**Incorrect (wrapper blocked by data fetching):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
async function Page() {
|
|
16
|
+
const data = await fetchData() // Blocks entire page
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
<div>Sidebar</div>
|
|
21
|
+
<div>Header</div>
|
|
22
|
+
<div>
|
|
23
|
+
<DataDisplay data={data} />
|
|
24
|
+
</div>
|
|
25
|
+
<div>Footer</div>
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The entire layout waits for data even though only the middle section needs it.
|
|
32
|
+
|
|
33
|
+
**Correct (wrapper shows immediately, data streams in):**
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
function Page() {
|
|
37
|
+
return (
|
|
38
|
+
<div>
|
|
39
|
+
<div>Sidebar</div>
|
|
40
|
+
<div>Header</div>
|
|
41
|
+
<div>
|
|
42
|
+
<Suspense fallback={<Skeleton />}>
|
|
43
|
+
<DataDisplay />
|
|
44
|
+
</Suspense>
|
|
45
|
+
</div>
|
|
46
|
+
<div>Footer</div>
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function DataDisplay() {
|
|
52
|
+
const data = await fetchData() // Only blocks this component
|
|
53
|
+
return <div>{data.content}</div>
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Sidebar, Header, and Footer render immediately. Only DataDisplay waits for data.
|
|
58
|
+
|
|
59
|
+
**Alternative (share promise across components):**
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
function Page() {
|
|
63
|
+
// Start fetch immediately, but don't await
|
|
64
|
+
const dataPromise = fetchData()
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div>
|
|
68
|
+
<div>Sidebar</div>
|
|
69
|
+
<div>Header</div>
|
|
70
|
+
<Suspense fallback={<Skeleton />}>
|
|
71
|
+
<DataDisplay dataPromise={dataPromise} />
|
|
72
|
+
<DataSummary dataPromise={dataPromise} />
|
|
73
|
+
</Suspense>
|
|
74
|
+
<div>Footer</div>
|
|
75
|
+
</div>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function DataDisplay({ dataPromise }: { dataPromise: Promise<Data> }) {
|
|
80
|
+
const data = use(dataPromise) // Unwraps the promise
|
|
81
|
+
return <div>{data.content}</div>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function DataSummary({ dataPromise }: { dataPromise: Promise<Data> }) {
|
|
85
|
+
const data = use(dataPromise) // Reuses the same promise
|
|
86
|
+
return <div>{data.summary}</div>
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Both components share the same promise, so only one fetch occurs. Layout renders immediately while both components wait together.
|
|
91
|
+
|
|
92
|
+
**When NOT to use this pattern:**
|
|
93
|
+
|
|
94
|
+
- Critical data needed for layout decisions (affects positioning)
|
|
95
|
+
- SEO-critical content above the fold
|
|
96
|
+
- Small, fast queries where suspense overhead isn't worth it
|
|
97
|
+
- When you want to avoid layout shift (loading → content jump)
|
|
98
|
+
|
|
99
|
+
**Trade-off:** Faster initial paint vs potential layout shift. Choose based on your UX priorities.
|