create-quadrokit 0.3.2 → 0.3.4

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.
Files changed (92) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/template-common/.agents/skills/quadro-paged-collection/SKILL.md +33 -0
  4. package/template-common/.agents/skills/vercel-composition-patterns/AGENTS.md +946 -0
  5. package/template-common/.agents/skills/vercel-composition-patterns/README.md +60 -0
  6. package/template-common/.agents/skills/vercel-composition-patterns/SKILL.md +89 -0
  7. package/template-common/.agents/skills/vercel-composition-patterns/rules/_sections.md +29 -0
  8. package/template-common/.agents/skills/vercel-composition-patterns/rules/_template.md +24 -0
  9. package/template-common/.agents/skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
  10. package/template-common/.agents/skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
  11. package/template-common/.agents/skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
  12. package/template-common/.agents/skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
  13. package/template-common/.agents/skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
  14. package/template-common/.agents/skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
  15. package/template-common/.agents/skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
  16. package/template-common/.agents/skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
  17. package/template-common/.agents/skills/vercel-react-best-practices/AGENTS.md +3750 -0
  18. package/template-common/.agents/skills/vercel-react-best-practices/README.md +123 -0
  19. package/template-common/.agents/skills/vercel-react-best-practices/SKILL.md +148 -0
  20. package/template-common/.agents/skills/vercel-react-best-practices/rules/_sections.md +46 -0
  21. package/template-common/.agents/skills/vercel-react-best-practices/rules/_template.md +28 -0
  22. package/template-common/.agents/skills/vercel-react-best-practices/rules/advanced-effect-event-deps.md +56 -0
  23. package/template-common/.agents/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  24. package/template-common/.agents/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
  25. package/template-common/.agents/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
  26. package/template-common/.agents/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
  27. package/template-common/.agents/skills/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
  28. package/template-common/.agents/skills/vercel-react-best-practices/rules/async-defer-await.md +82 -0
  29. package/template-common/.agents/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
  30. package/template-common/.agents/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
  31. package/template-common/.agents/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
  32. package/template-common/.agents/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +60 -0
  33. package/template-common/.agents/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
  34. package/template-common/.agents/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
  35. package/template-common/.agents/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
  36. package/template-common/.agents/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
  37. package/template-common/.agents/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
  38. package/template-common/.agents/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
  39. package/template-common/.agents/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
  40. package/template-common/.agents/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
  41. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
  42. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
  43. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
  44. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
  45. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
  46. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
  47. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-flatmap-filter.md +60 -0
  48. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
  49. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
  50. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
  51. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
  52. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-request-idle-callback.md +105 -0
  53. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
  54. package/template-common/.agents/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
  55. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
  56. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  57. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
  58. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
  59. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  60. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
  61. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
  62. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-resource-hints.md +85 -0
  63. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-script-defer-async.md +68 -0
  64. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
  65. package/template-common/.agents/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
  66. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
  67. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
  68. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  69. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
  70. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
  71. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  72. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
  73. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
  74. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  75. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-no-inline-components.md +82 -0
  76. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  77. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
  78. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
  79. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-use-deferred-value.md +59 -0
  80. package/template-common/.agents/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  81. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
  82. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
  83. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
  84. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
  85. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
  86. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-hoist-static-io.md +149 -0
  87. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-no-shared-module-state.md +50 -0
  88. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
  89. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +34 -0
  90. package/template-common/.agents/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
  91. package/template-common/.agents/skills/web-design-guidelines/SKILL.md +39 -0
  92. package/template-common/skills-lock.json +20 -0
@@ -0,0 +1,123 @@
1
+ # React Best Practices
2
+
3
+ A structured repository for creating and maintaining React Best Practices optimized for agents and LLMs.
4
+
5
+ ## Structure
6
+
7
+ - `rules/` - Individual rule files (one per rule)
8
+ - `_sections.md` - Section metadata (titles, impacts, descriptions)
9
+ - `_template.md` - Template for creating new rules
10
+ - `area-description.md` - Individual rule files
11
+ - `src/` - Build scripts and utilities
12
+ - `metadata.json` - Document metadata (version, organization, abstract)
13
+ - __`AGENTS.md`__ - Compiled output (generated)
14
+ - __`test-cases.json`__ - Test cases for LLM evaluation (generated)
15
+
16
+ ## Getting Started
17
+
18
+ 1. Install dependencies:
19
+ ```bash
20
+ pnpm install
21
+ ```
22
+
23
+ 2. Build AGENTS.md from rules:
24
+ ```bash
25
+ pnpm build
26
+ ```
27
+
28
+ 3. Validate rule files:
29
+ ```bash
30
+ pnpm validate
31
+ ```
32
+
33
+ 4. Extract test cases:
34
+ ```bash
35
+ pnpm extract-tests
36
+ ```
37
+
38
+ ## Creating a New Rule
39
+
40
+ 1. Copy `rules/_template.md` to `rules/area-description.md`
41
+ 2. Choose the appropriate area prefix:
42
+ - `async-` for Eliminating Waterfalls (Section 1)
43
+ - `bundle-` for Bundle Size Optimization (Section 2)
44
+ - `server-` for Server-Side Performance (Section 3)
45
+ - `client-` for Client-Side Data Fetching (Section 4)
46
+ - `rerender-` for Re-render Optimization (Section 5)
47
+ - `rendering-` for Rendering Performance (Section 6)
48
+ - `js-` for JavaScript Performance (Section 7)
49
+ - `advanced-` for Advanced Patterns (Section 8)
50
+ 3. Fill in the frontmatter and content
51
+ 4. Ensure you have clear examples with explanations
52
+ 5. Run `pnpm build` to regenerate AGENTS.md and test-cases.json
53
+
54
+ ## Rule File Structure
55
+
56
+ Each rule file should follow this structure:
57
+
58
+ ```markdown
59
+ ---
60
+ title: Rule Title Here
61
+ impact: MEDIUM
62
+ impactDescription: Optional description
63
+ tags: tag1, tag2, tag3
64
+ ---
65
+
66
+ ## Rule Title Here
67
+
68
+ Brief explanation of the rule and why it matters.
69
+
70
+ **Incorrect (description of what's wrong):**
71
+
72
+ ```typescript
73
+ // Bad code example
74
+ ```
75
+
76
+ **Correct (description of what's right):**
77
+
78
+ ```typescript
79
+ // Good code example
80
+ ```
81
+
82
+ Optional explanatory text after examples.
83
+
84
+ Reference: [Link](https://example.com)
85
+
86
+ ## File Naming Convention
87
+
88
+ - Files starting with `_` are special (excluded from build)
89
+ - Rule files: `area-description.md` (e.g., `async-parallel.md`)
90
+ - Section is automatically inferred from filename prefix
91
+ - Rules are sorted alphabetically by title within each section
92
+ - IDs (e.g., 1.1, 1.2) are auto-generated during build
93
+
94
+ ## Impact Levels
95
+
96
+ - `CRITICAL` - Highest priority, major performance gains
97
+ - `HIGH` - Significant performance improvements
98
+ - `MEDIUM-HIGH` - Moderate-high gains
99
+ - `MEDIUM` - Moderate performance improvements
100
+ - `LOW-MEDIUM` - Low-medium gains
101
+ - `LOW` - Incremental improvements
102
+
103
+ ## Scripts
104
+
105
+ - `pnpm build` - Compile rules into AGENTS.md
106
+ - `pnpm validate` - Validate all rule files
107
+ - `pnpm extract-tests` - Extract test cases for LLM evaluation
108
+ - `pnpm dev` - Build and validate
109
+
110
+ ## Contributing
111
+
112
+ When adding or modifying rules:
113
+
114
+ 1. Use the correct filename prefix for your section
115
+ 2. Follow the `_template.md` structure
116
+ 3. Include clear bad/good examples with explanations
117
+ 4. Add appropriate tags
118
+ 5. Run `pnpm build` to regenerate AGENTS.md and test-cases.json
119
+ 6. Rules are automatically sorted by title - no need to manage numbers!
120
+
121
+ ## Acknowledgments
122
+
123
+ Originally created by [@shuding](https://x.com/shuding) at [Vercel](https://vercel.com).
@@ -0,0 +1,148 @@
1
+ ---
2
+ name: vercel-react-best-practices
3
+ description: React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
4
+ license: MIT
5
+ metadata:
6
+ author: vercel
7
+ version: "1.0.0"
8
+ ---
9
+
10
+ # Vercel React Best Practices
11
+
12
+ Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 69 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
13
+
14
+ ## When to Apply
15
+
16
+ Reference these guidelines when:
17
+ - Writing new React components or Next.js pages
18
+ - Implementing data fetching (client or server-side)
19
+ - Reviewing code for performance issues
20
+ - Refactoring existing React/Next.js code
21
+ - Optimizing bundle size or load times
22
+
23
+ ## Rule Categories by Priority
24
+
25
+ | Priority | Category | Impact | Prefix |
26
+ |----------|----------|--------|--------|
27
+ | 1 | Eliminating Waterfalls | CRITICAL | `async-` |
28
+ | 2 | Bundle Size Optimization | CRITICAL | `bundle-` |
29
+ | 3 | Server-Side Performance | HIGH | `server-` |
30
+ | 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |
31
+ | 5 | Re-render Optimization | MEDIUM | `rerender-` |
32
+ | 6 | Rendering Performance | MEDIUM | `rendering-` |
33
+ | 7 | JavaScript Performance | LOW-MEDIUM | `js-` |
34
+ | 8 | Advanced Patterns | LOW | `advanced-` |
35
+
36
+ ## Quick Reference
37
+
38
+ ### 1. Eliminating Waterfalls (CRITICAL)
39
+
40
+ - `async-cheap-condition-before-await` - Check cheap sync conditions before awaiting flags or remote values
41
+ - `async-defer-await` - Move await into branches where actually used
42
+ - `async-parallel` - Use Promise.all() for independent operations
43
+ - `async-dependencies` - Use better-all for partial dependencies
44
+ - `async-api-routes` - Start promises early, await late in API routes
45
+ - `async-suspense-boundaries` - Use Suspense to stream content
46
+
47
+ ### 2. Bundle Size Optimization (CRITICAL)
48
+
49
+ - `bundle-barrel-imports` - Import directly, avoid barrel files
50
+ - `bundle-dynamic-imports` - Use next/dynamic for heavy components
51
+ - `bundle-defer-third-party` - Load analytics/logging after hydration
52
+ - `bundle-conditional` - Load modules only when feature is activated
53
+ - `bundle-preload` - Preload on hover/focus for perceived speed
54
+
55
+ ### 3. Server-Side Performance (HIGH)
56
+
57
+ - `server-auth-actions` - Authenticate server actions like API routes
58
+ - `server-cache-react` - Use React.cache() for per-request deduplication
59
+ - `server-cache-lru` - Use LRU cache for cross-request caching
60
+ - `server-dedup-props` - Avoid duplicate serialization in RSC props
61
+ - `server-hoist-static-io` - Hoist static I/O (fonts, logos) to module level
62
+ - `server-no-shared-module-state` - Avoid module-level mutable request state in RSC/SSR
63
+ - `server-serialization` - Minimize data passed to client components
64
+ - `server-parallel-fetching` - Restructure components to parallelize fetches
65
+ - `server-parallel-nested-fetching` - Chain nested fetches per item in Promise.all
66
+ - `server-after-nonblocking` - Use after() for non-blocking operations
67
+
68
+ ### 4. Client-Side Data Fetching (MEDIUM-HIGH)
69
+
70
+ - `client-swr-dedup` - Use SWR for automatic request deduplication
71
+ - `client-event-listeners` - Deduplicate global event listeners
72
+ - `client-passive-event-listeners` - Use passive listeners for scroll
73
+ - `client-localstorage-schema` - Version and minimize localStorage data
74
+
75
+ ### 5. Re-render Optimization (MEDIUM)
76
+
77
+ - `rerender-defer-reads` - Don't subscribe to state only used in callbacks
78
+ - `rerender-memo` - Extract expensive work into memoized components
79
+ - `rerender-memo-with-default-value` - Hoist default non-primitive props
80
+ - `rerender-dependencies` - Use primitive dependencies in effects
81
+ - `rerender-derived-state` - Subscribe to derived booleans, not raw values
82
+ - `rerender-derived-state-no-effect` - Derive state during render, not effects
83
+ - `rerender-functional-setstate` - Use functional setState for stable callbacks
84
+ - `rerender-lazy-state-init` - Pass function to useState for expensive values
85
+ - `rerender-simple-expression-in-memo` - Avoid memo for simple primitives
86
+ - `rerender-split-combined-hooks` - Split hooks with independent dependencies
87
+ - `rerender-move-effect-to-event` - Put interaction logic in event handlers
88
+ - `rerender-transitions` - Use startTransition for non-urgent updates
89
+ - `rerender-use-deferred-value` - Defer expensive renders to keep input responsive
90
+ - `rerender-use-ref-transient-values` - Use refs for transient frequent values
91
+ - `rerender-no-inline-components` - Don't define components inside components
92
+
93
+ ### 6. Rendering Performance (MEDIUM)
94
+
95
+ - `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element
96
+ - `rendering-content-visibility` - Use content-visibility for long lists
97
+ - `rendering-hoist-jsx` - Extract static JSX outside components
98
+ - `rendering-svg-precision` - Reduce SVG coordinate precision
99
+ - `rendering-hydration-no-flicker` - Use inline script for client-only data
100
+ - `rendering-hydration-suppress-warning` - Suppress expected mismatches
101
+ - `rendering-activity` - Use Activity component for show/hide
102
+ - `rendering-conditional-render` - Use ternary, not && for conditionals
103
+ - `rendering-usetransition-loading` - Prefer useTransition for loading state
104
+ - `rendering-resource-hints` - Use React DOM resource hints for preloading
105
+ - `rendering-script-defer-async` - Use defer or async on script tags
106
+
107
+ ### 7. JavaScript Performance (LOW-MEDIUM)
108
+
109
+ - `js-batch-dom-css` - Group CSS changes via classes or cssText
110
+ - `js-index-maps` - Build Map for repeated lookups
111
+ - `js-cache-property-access` - Cache object properties in loops
112
+ - `js-cache-function-results` - Cache function results in module-level Map
113
+ - `js-cache-storage` - Cache localStorage/sessionStorage reads
114
+ - `js-combine-iterations` - Combine multiple filter/map into one loop
115
+ - `js-length-check-first` - Check array length before expensive comparison
116
+ - `js-early-exit` - Return early from functions
117
+ - `js-hoist-regexp` - Hoist RegExp creation outside loops
118
+ - `js-min-max-loop` - Use loop for min/max instead of sort
119
+ - `js-set-map-lookups` - Use Set/Map for O(1) lookups
120
+ - `js-tosorted-immutable` - Use toSorted() for immutability
121
+ - `js-flatmap-filter` - Use flatMap to map and filter in one pass
122
+ - `js-request-idle-callback` - Defer non-critical work to browser idle time
123
+
124
+ ### 8. Advanced Patterns (LOW)
125
+
126
+ - `advanced-effect-event-deps` - Don't put `useEffectEvent` results in effect deps
127
+ - `advanced-event-handler-refs` - Store event handlers in refs
128
+ - `advanced-init-once` - Initialize app once per app load
129
+ - `advanced-use-latest` - useLatest for stable callback refs
130
+
131
+ ## How to Use
132
+
133
+ Read individual rule files for detailed explanations and code examples:
134
+
135
+ ```
136
+ rules/async-parallel.md
137
+ rules/bundle-barrel-imports.md
138
+ ```
139
+
140
+ Each rule file contains:
141
+ - Brief explanation of why it matters
142
+ - Incorrect code example with explanation
143
+ - Correct code example with explanation
144
+ - Additional context and references
145
+
146
+ ## Full Compiled Document
147
+
148
+ For the complete guide with all rules expanded: `AGENTS.md`
@@ -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,56 @@
1
+ ---
2
+ title: Do Not Put Effect Events in Dependency Arrays
3
+ impact: LOW
4
+ impactDescription: avoids unnecessary effect re-runs and lint errors
5
+ tags: advanced, hooks, useEffectEvent, dependencies, effects
6
+ ---
7
+
8
+ ## Do Not Put Effect Events in Dependency Arrays
9
+
10
+ Effect Event functions do not have a stable identity. Their identity intentionally changes on every render. Do not include the function returned by `useEffectEvent` in a `useEffect` dependency array. Keep the actual reactive values as dependencies and call the Effect Event from inside the effect body or subscriptions created by that effect.
11
+
12
+ **Incorrect (Effect Event added as a dependency):**
13
+
14
+ ```tsx
15
+ import { useEffect, useEffectEvent } from 'react'
16
+
17
+ function ChatRoom({ roomId, onConnected }: {
18
+ roomId: string
19
+ onConnected: () => void
20
+ }) {
21
+ const handleConnected = useEffectEvent(onConnected)
22
+
23
+ useEffect(() => {
24
+ const connection = createConnection(roomId)
25
+ connection.on('connected', handleConnected)
26
+ connection.connect()
27
+
28
+ return () => connection.disconnect()
29
+ }, [roomId, handleConnected])
30
+ }
31
+ ```
32
+
33
+ Including the Effect Event in dependencies makes the effect re-run every render and triggers the React Hooks lint rule.
34
+
35
+ **Correct (depend on reactive values, not the Effect Event):**
36
+
37
+ ```tsx
38
+ import { useEffect, useEffectEvent } from 'react'
39
+
40
+ function ChatRoom({ roomId, onConnected }: {
41
+ roomId: string
42
+ onConnected: () => void
43
+ }) {
44
+ const handleConnected = useEffectEvent(onConnected)
45
+
46
+ useEffect(() => {
47
+ const connection = createConnection(roomId)
48
+ connection.on('connected', handleConnected)
49
+ connection.connect()
50
+
51
+ return () => connection.disconnect()
52
+ }, [roomId])
53
+ }
54
+ ```
55
+
56
+ Reference: [React useEffectEvent: Effect Event in deps](https://react.dev/reference/react/useEffectEvent#effect-event-in-deps)
@@ -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,37 @@
1
+ ---
2
+ title: Check Cheap Conditions Before Async Flags
3
+ impact: HIGH
4
+ impactDescription: avoids unnecessary async work when a synchronous guard already fails
5
+ tags: async, await, feature-flags, short-circuit, conditional
6
+ ---
7
+
8
+ ## Check Cheap Conditions Before Async Flags
9
+
10
+ When a branch uses `await` for a flag or remote value and also requires a **cheap synchronous** condition (local props, request metadata, already-loaded state), evaluate the cheap condition **first**. Otherwise you pay for the async call even when the compound condition can never be true.
11
+
12
+ This is a specialization of [Defer Await Until Needed](./async-defer-await.md) for `flag && cheapCondition` style checks.
13
+
14
+ **Incorrect:**
15
+
16
+ ```typescript
17
+ const someFlag = await getFlag()
18
+
19
+ if (someFlag && someCondition) {
20
+ // ...
21
+ }
22
+ ```
23
+
24
+ **Correct:**
25
+
26
+ ```typescript
27
+ if (someCondition) {
28
+ const someFlag = await getFlag()
29
+ if (someFlag) {
30
+ // ...
31
+ }
32
+ }
33
+ ```
34
+
35
+ This matters when `getFlag` hits the network, a feature-flag service, or `React.cache` / DB work: skipping it when `someCondition` is false removes that cost on the cold path.
36
+
37
+ Keep the original order if `someCondition` is expensive, depends on the flag, or you must run side effects in a fixed order.