create-claudecraft 1.0.0
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/LICENSE +21 -0
- package/README.md +194 -0
- package/bin/cli.js +2 -0
- package/dist/constants.d.ts +71 -0
- package/dist/constants.js +128 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +229 -0
- package/dist/ink-prompts.d.ts +12 -0
- package/dist/ink-prompts.js +363 -0
- package/dist/prompts.d.ts +16 -0
- package/dist/prompts.js +434 -0
- package/dist/scaffold.d.ts +19 -0
- package/dist/scaffold.js +303 -0
- package/dist/ui.d.ts +27 -0
- package/dist/ui.js +254 -0
- package/package.json +74 -0
- package/templates/app/App.tsx +21 -0
- package/templates/base/CLAUDE.md +332 -0
- package/templates/base/eslint.config.js +28 -0
- package/templates/base/index.html +17 -0
- package/templates/base/package.json +43 -0
- package/templates/base/postcss.config.js +6 -0
- package/templates/base/tailwind.config.js +81 -0
- package/templates/base/tsconfig.json +25 -0
- package/templates/base/vite.config.ts +16 -0
- package/templates/commands/brainstorm.md +6 -0
- package/templates/commands/build.md +41 -0
- package/templates/commands/execute-plan.md +6 -0
- package/templates/commands/lint.md +41 -0
- package/templates/commands/ralph.md +113 -0
- package/templates/commands/typecheck.md +44 -0
- package/templates/commands/write-plan.md +6 -0
- package/templates/components/ErrorBoundary.tsx +49 -0
- package/templates/components/ui/Button.tsx +60 -0
- package/templates/components/ui/CodeBlock.tsx +46 -0
- package/templates/components/ui/CopyCommand.tsx +38 -0
- package/templates/components/ui/FilePreview.tsx +46 -0
- package/templates/components/ui/SkipLink.tsx +7 -0
- package/templates/components/ui/ThemeSelector.tsx +41 -0
- package/templates/components/ui/UICarousel.tsx +309 -0
- package/templates/context/ThemeContext.tsx +61 -0
- package/templates/homepage/HomePage.tsx +534 -0
- package/templates/homepage/NotFoundPage.tsx +17 -0
- package/templates/hooks/README.md +82 -0
- package/templates/hooks/check-branch.js +27 -0
- package/templates/hooks/typecheck-after-edit.js +51 -0
- package/templates/index.css +67 -0
- package/templates/lib/utils.ts +9 -0
- package/templates/main.tsx +16 -0
- package/templates/settings/MCP_SETUP.md +76 -0
- package/templates/settings/settings.json +16 -0
- package/templates/settings/settings.local.json +37 -0
- package/templates/skills/design/a11y-audit/SKILL.md +173 -0
- package/templates/skills/design/design-polish/SKILL.md +75 -0
- package/templates/skills/design/figma-to-code/SKILL.md +157 -0
- package/templates/skills/design/json-ld/SKILL.md +125 -0
- package/templates/skills/design/microcopy/SKILL.md +197 -0
- package/templates/skills/design/og-image/SKILL.md +157 -0
- package/templates/skills/design/ralph-wiggum-loops/SKILL.md +299 -0
- package/templates/skills/design/react-best-practices/SKILL.md +106 -0
- package/templates/skills/design/react-best-practices/references/react-performance-guidelines.md +143 -0
- package/templates/skills/design/seo-review/SKILL.md +96 -0
- package/templates/skills/design/sitemap-generator/SKILL.md +66 -0
- package/templates/skills/design/testing-patterns/SKILL.md +276 -0
- package/templates/skills/design/ui-skills/SKILL.md +85 -0
- package/templates/skills/design/visual-iteration/SKILL.md +88 -0
- package/templates/skills/workflow/brainstorming/SKILL.md +54 -0
- package/templates/skills/workflow/dispatching-parallel-agents/SKILL.md +180 -0
- package/templates/skills/workflow/executing-plans/SKILL.md +76 -0
- package/templates/skills/workflow/finishing-a-development-branch/SKILL.md +200 -0
- package/templates/skills/workflow/receiving-code-review/SKILL.md +213 -0
- package/templates/skills/workflow/requesting-code-review/SKILL.md +105 -0
- package/templates/skills/workflow/requesting-code-review/code-reviewer.md +146 -0
- package/templates/skills/workflow/subagent-driven-development/SKILL.md +240 -0
- package/templates/skills/workflow/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/templates/skills/workflow/subagent-driven-development/implementer-prompt.md +78 -0
- package/templates/skills/workflow/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/templates/skills/workflow/systematic-debugging/CREATION-LOG.md +119 -0
- package/templates/skills/workflow/systematic-debugging/SKILL.md +296 -0
- package/templates/skills/workflow/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/templates/skills/workflow/systematic-debugging/condition-based-waiting.md +115 -0
- package/templates/skills/workflow/systematic-debugging/defense-in-depth.md +122 -0
- package/templates/skills/workflow/systematic-debugging/find-polluter.sh +63 -0
- package/templates/skills/workflow/systematic-debugging/root-cause-tracing.md +169 -0
- package/templates/skills/workflow/systematic-debugging/test-academic.md +14 -0
- package/templates/skills/workflow/systematic-debugging/test-pressure-1.md +58 -0
- package/templates/skills/workflow/systematic-debugging/test-pressure-2.md +68 -0
- package/templates/skills/workflow/systematic-debugging/test-pressure-3.md +69 -0
- package/templates/skills/workflow/test-driven-development/SKILL.md +371 -0
- package/templates/skills/workflow/test-driven-development/testing-anti-patterns.md +299 -0
- package/templates/skills/workflow/using-git-worktrees/SKILL.md +217 -0
- package/templates/skills/workflow/using-superpowers/SKILL.md +87 -0
- package/templates/skills/workflow/verification-before-completion/SKILL.md +139 -0
- package/templates/skills/workflow/writing-plans/SKILL.md +116 -0
- package/templates/skills/workflow/writing-skills/SKILL.md +655 -0
- package/templates/skills/workflow/writing-skills/anthropic-best-practices.md +1150 -0
- package/templates/skills/workflow/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/templates/skills/workflow/writing-skills/graphviz-conventions.dot +172 -0
- package/templates/skills/workflow/writing-skills/persuasion-principles.md +187 -0
- package/templates/skills/workflow/writing-skills/render-graphs.js +168 -0
- package/templates/skills/workflow/writing-skills/testing-skills-with-subagents.md +384 -0
- package/templates/types/index.ts +17 -0
- package/templates/vite-env.d.ts +1 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Ralph Wiggum Loops - The Ultimate Superpower
|
|
2
|
+
|
|
3
|
+
> "Ralph is a bash loop. You give Claude a task, it works on it, and when it tries to exit, a Stop hook blocks the exit and feeds the same prompt back in. Each iteration builds on the last."
|
|
4
|
+
> — Geoffrey Huntley, creator of the technique
|
|
5
|
+
|
|
6
|
+
## What Is It?
|
|
7
|
+
|
|
8
|
+
The Ralph Wiggum technique creates a **self-correcting feedback loop** where Claude Code:
|
|
9
|
+
1. Works on your task
|
|
10
|
+
2. Tries to exit
|
|
11
|
+
3. Gets blocked and fed the same prompt again
|
|
12
|
+
4. Sees what it built, notices what's broken, fixes it
|
|
13
|
+
5. Repeats until done
|
|
14
|
+
|
|
15
|
+
Named after the Simpsons character who keeps going despite everything.
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
### Install the Official Plugin
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Add Anthropic's plugin marketplace (if not already added)
|
|
23
|
+
/plugin marketplace add anthropics/claude-code
|
|
24
|
+
|
|
25
|
+
# Install ralph-wiggum
|
|
26
|
+
/plugin install ralph-wiggum@claude-plugins-official
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Verify Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
/ralph-loop --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Basic Usage
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
/ralph-loop "<your prompt>" --completion-promise "COMPLETE" --max-iterations 20
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Parameters:**
|
|
42
|
+
- `--completion-promise`: Exact text that signals "I'm done"
|
|
43
|
+
- `--max-iterations`: Safety limit (always set this!)
|
|
44
|
+
|
|
45
|
+
**Cancel anytime:**
|
|
46
|
+
```bash
|
|
47
|
+
/cancel-ralph
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Pre-Configured Loops for Designers
|
|
53
|
+
|
|
54
|
+
### 1. Component Builder Loop
|
|
55
|
+
|
|
56
|
+
Build a complete component from a description:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
/ralph-loop "Build a [COMPONENT NAME] component.
|
|
60
|
+
|
|
61
|
+
Requirements:
|
|
62
|
+
- Use DaisyUI + Tailwind CSS
|
|
63
|
+
- Follow existing patterns in src/components/ui/
|
|
64
|
+
- Include hover, focus, and active states
|
|
65
|
+
- Make it responsive (mobile, tablet, desktop)
|
|
66
|
+
- Add TypeScript props interface
|
|
67
|
+
|
|
68
|
+
Verification steps each iteration:
|
|
69
|
+
1. Check if component file exists
|
|
70
|
+
2. Run: bun run typecheck
|
|
71
|
+
3. Run: bun run lint
|
|
72
|
+
4. If errors, fix them
|
|
73
|
+
5. When all checks pass, output: <promise>COMPLETE</promise>
|
|
74
|
+
|
|
75
|
+
If after 10 iterations not complete, document blockers and output: <promise>COMPLETE</promise>" --completion-promise "COMPLETE" --max-iterations 15
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. Design System Audit Loop
|
|
79
|
+
|
|
80
|
+
Audit and fix design consistency:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
/ralph-loop "Audit src/components for design system consistency.
|
|
84
|
+
|
|
85
|
+
For each component, check and fix:
|
|
86
|
+
- Uses DaisyUI semantic colors (not hardcoded hex)
|
|
87
|
+
- Uses spacing scale (4, 8, 16, 24, 32px)
|
|
88
|
+
- Has proper hover/focus states
|
|
89
|
+
- Typography follows hierarchy
|
|
90
|
+
|
|
91
|
+
Process:
|
|
92
|
+
1. List all components in src/components/
|
|
93
|
+
2. Review each one
|
|
94
|
+
3. Fix inconsistencies found
|
|
95
|
+
4. Run typecheck and lint
|
|
96
|
+
5. Move to next component
|
|
97
|
+
6. When ALL components reviewed and fixed, output: <promise>COMPLETE</promise>" --completion-promise "COMPLETE" --max-iterations 30
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 3. Responsive Fix Loop
|
|
101
|
+
|
|
102
|
+
Make a page fully responsive:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
/ralph-loop "Make [PAGE NAME] fully responsive.
|
|
106
|
+
|
|
107
|
+
Breakpoints to support:
|
|
108
|
+
- Mobile: 375px
|
|
109
|
+
- Tablet: 768px
|
|
110
|
+
- Desktop: 1280px+
|
|
111
|
+
|
|
112
|
+
Process each section:
|
|
113
|
+
1. Review current responsive behavior
|
|
114
|
+
2. Fix layout issues at each breakpoint
|
|
115
|
+
3. Ensure touch targets are 44px+ on mobile
|
|
116
|
+
4. Run typecheck
|
|
117
|
+
5. Move to next section
|
|
118
|
+
6. When entire page is responsive, output: <promise>COMPLETE</promise>" --completion-promise "COMPLETE" --max-iterations 20
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 4. Polish Loop
|
|
122
|
+
|
|
123
|
+
Automated polish pass:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
/ralph-loop "Polish pass on [FILE/COMPONENT].
|
|
127
|
+
|
|
128
|
+
Check and fix:
|
|
129
|
+
- [ ] Consistent spacing
|
|
130
|
+
- [ ] Proper typography hierarchy
|
|
131
|
+
- [ ] Hover states on interactive elements
|
|
132
|
+
- [ ] Focus states for accessibility
|
|
133
|
+
- [ ] Smooth transitions (150-300ms)
|
|
134
|
+
- [ ] No hardcoded colors
|
|
135
|
+
|
|
136
|
+
After each fix:
|
|
137
|
+
1. Run bun run typecheck
|
|
138
|
+
2. Run bun run lint
|
|
139
|
+
3. If errors, fix them
|
|
140
|
+
|
|
141
|
+
When all checklist items done and no errors, output: <promise>COMPLETE</promise>" --completion-promise "COMPLETE" --max-iterations 15
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 5. Feature Build Loop
|
|
145
|
+
|
|
146
|
+
Build a complete feature overnight:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
/ralph-loop "Build [FEATURE NAME] feature.
|
|
150
|
+
|
|
151
|
+
Requirements:
|
|
152
|
+
[List your requirements here]
|
|
153
|
+
|
|
154
|
+
Phases:
|
|
155
|
+
1. Create component structure
|
|
156
|
+
2. Implement core functionality
|
|
157
|
+
3. Add styling with DaisyUI
|
|
158
|
+
4. Make responsive
|
|
159
|
+
5. Run all checks
|
|
160
|
+
|
|
161
|
+
Each iteration:
|
|
162
|
+
- Work on current phase
|
|
163
|
+
- Run: bun run typecheck && bun run lint
|
|
164
|
+
- If errors, fix them
|
|
165
|
+
- If phase complete, move to next
|
|
166
|
+
- When all phases done and checks pass, output: <promise>COMPLETE</promise>
|
|
167
|
+
|
|
168
|
+
Escape hatch: After 25 iterations, document progress and blockers, then output: <promise>COMPLETE</promise>" --completion-promise "COMPLETE" --max-iterations 30
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Writing Good Ralph Prompts
|
|
174
|
+
|
|
175
|
+
### The Formula
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
[TASK DESCRIPTION]
|
|
179
|
+
|
|
180
|
+
Requirements:
|
|
181
|
+
- [Specific requirement 1]
|
|
182
|
+
- [Specific requirement 2]
|
|
183
|
+
|
|
184
|
+
Verification each iteration:
|
|
185
|
+
1. [Check 1]
|
|
186
|
+
2. [Check 2]
|
|
187
|
+
3. If errors, fix them
|
|
188
|
+
|
|
189
|
+
Completion criteria:
|
|
190
|
+
- [Measurable outcome 1]
|
|
191
|
+
- [Measurable outcome 2]
|
|
192
|
+
- When all criteria met, output: <promise>COMPLETE</promise>
|
|
193
|
+
|
|
194
|
+
Escape hatch:
|
|
195
|
+
After N iterations, if not complete, document blockers and output: <promise>COMPLETE</promise>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Good vs Bad Prompts
|
|
199
|
+
|
|
200
|
+
❌ **Bad:**
|
|
201
|
+
```
|
|
202
|
+
Make the homepage look better
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
✅ **Good:**
|
|
206
|
+
```
|
|
207
|
+
Improve homepage visual hierarchy.
|
|
208
|
+
|
|
209
|
+
Specific changes:
|
|
210
|
+
- Increase hero heading to text-4xl on mobile, text-6xl on desktop
|
|
211
|
+
- Add 32px gap between sections
|
|
212
|
+
- Ensure CTA button has hover state with scale-105 transform
|
|
213
|
+
- Add subtle shadow to feature cards
|
|
214
|
+
|
|
215
|
+
Verify each iteration:
|
|
216
|
+
- Run bun run typecheck
|
|
217
|
+
- Run bun run lint
|
|
218
|
+
- Fix any errors
|
|
219
|
+
|
|
220
|
+
When all changes implemented and checks pass, output: <promise>COMPLETE</promise>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Safety Guidelines
|
|
226
|
+
|
|
227
|
+
### Always Set Max Iterations
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# GOOD - has safety limit
|
|
231
|
+
/ralph-loop "..." --max-iterations 20
|
|
232
|
+
|
|
233
|
+
# DANGEROUS - could run forever
|
|
234
|
+
/ralph-loop "..."
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Include Escape Hatches
|
|
238
|
+
|
|
239
|
+
Always add fallback instructions:
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
After 20 iterations, if not complete:
|
|
243
|
+
- Document what's blocking progress
|
|
244
|
+
- List what was attempted
|
|
245
|
+
- Output: <promise>COMPLETE</promise>
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Monitor Costs
|
|
249
|
+
|
|
250
|
+
Ralph loops can consume significant API credits. For reference:
|
|
251
|
+
- Simple component: ~$2-5
|
|
252
|
+
- Full feature: ~$10-30
|
|
253
|
+
- Overnight builds: ~$50-300
|
|
254
|
+
|
|
255
|
+
### Start Small
|
|
256
|
+
|
|
257
|
+
Test your prompt with `--max-iterations 5` first to verify it works, then increase.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Real-World Results
|
|
262
|
+
|
|
263
|
+
- **YC Hackathon**: 6 repositories shipped overnight for $297
|
|
264
|
+
- **Contract Work**: $50k project completed autonomously
|
|
265
|
+
- **CURSED Lang**: Entire programming language built over 3 months
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## When to Use Ralph
|
|
270
|
+
|
|
271
|
+
✅ **Perfect for:**
|
|
272
|
+
- Well-defined tasks with clear success criteria
|
|
273
|
+
- Tasks with automatic verification (tests, linting)
|
|
274
|
+
- Overnight/background builds
|
|
275
|
+
- Iterative refinement work
|
|
276
|
+
|
|
277
|
+
❌ **Not for:**
|
|
278
|
+
- Tasks requiring design decisions
|
|
279
|
+
- Unclear requirements
|
|
280
|
+
- Production debugging
|
|
281
|
+
- Anything needing human judgment mid-process
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Quick Reference
|
|
286
|
+
|
|
287
|
+
| Command | Description |
|
|
288
|
+
|---------|-------------|
|
|
289
|
+
| `/ralph-loop "<prompt>" --max-iterations N --completion-promise "TEXT"` | Start loop |
|
|
290
|
+
| `/cancel-ralph` | Stop active loop |
|
|
291
|
+
| `<promise>COMPLETE</promise>` | Standard completion signal |
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Philosophy
|
|
296
|
+
|
|
297
|
+
> "Don't aim for perfect on first try. Let the loop refine the work."
|
|
298
|
+
|
|
299
|
+
The Ralph Wiggum technique embodies **iteration over perfection**. Each failure is data. Each loop improves on the last. Success comes from persistent iteration, not first-try brilliance.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: 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
|
+
---
|
|
5
|
+
|
|
6
|
+
# React Best Practices
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Comprehensive performance optimization guide for React and Next.js applications, containing 40+ rules across 8 categories. Rules are prioritized by impact to guide automated refactoring and code generation.
|
|
11
|
+
|
|
12
|
+
## When to Apply
|
|
13
|
+
|
|
14
|
+
Reference these guidelines when:
|
|
15
|
+
- Writing new React components or Next.js pages
|
|
16
|
+
- Implementing data fetching (client or server-side)
|
|
17
|
+
- Reviewing code for performance issues
|
|
18
|
+
- Refactoring existing React/Next.js code
|
|
19
|
+
- Optimizing bundle size or load times
|
|
20
|
+
|
|
21
|
+
## Priority-Ordered Guidelines
|
|
22
|
+
|
|
23
|
+
Rules are prioritized by impact:
|
|
24
|
+
|
|
25
|
+
| Priority | Category | Impact |
|
|
26
|
+
|----------|----------|--------|
|
|
27
|
+
| 1 | Eliminating Waterfalls | CRITICAL |
|
|
28
|
+
| 2 | Bundle Size Optimization | CRITICAL |
|
|
29
|
+
| 3 | Server-Side Performance | HIGH |
|
|
30
|
+
| 4 | Client-Side Data Fetching | MEDIUM-HIGH |
|
|
31
|
+
| 5 | Re-render Optimization | MEDIUM |
|
|
32
|
+
| 6 | Rendering Performance | MEDIUM |
|
|
33
|
+
| 7 | JavaScript Performance | LOW-MEDIUM |
|
|
34
|
+
| 8 | Advanced Patterns | LOW |
|
|
35
|
+
|
|
36
|
+
## Quick Reference
|
|
37
|
+
|
|
38
|
+
### Critical Patterns (Apply First)
|
|
39
|
+
|
|
40
|
+
**Eliminate Waterfalls:**
|
|
41
|
+
- Defer await until needed (move into branches)
|
|
42
|
+
- Use `Promise.all()` for independent async operations
|
|
43
|
+
- Start promises early, await late
|
|
44
|
+
- Use `better-all` for partial dependencies
|
|
45
|
+
- Use Suspense boundaries to stream content
|
|
46
|
+
|
|
47
|
+
**Reduce Bundle Size:**
|
|
48
|
+
- Avoid barrel file imports (import directly from source)
|
|
49
|
+
- Use `next/dynamic` for heavy components
|
|
50
|
+
- Defer non-critical third-party libraries
|
|
51
|
+
- Preload based on user intent
|
|
52
|
+
|
|
53
|
+
### High-Impact Server Patterns
|
|
54
|
+
|
|
55
|
+
- Use `React.cache()` for per-request deduplication
|
|
56
|
+
- Use LRU cache for cross-request caching
|
|
57
|
+
- Minimize serialization at RSC boundaries
|
|
58
|
+
- Parallelize data fetching with component composition
|
|
59
|
+
|
|
60
|
+
### Medium-Impact Client Patterns
|
|
61
|
+
|
|
62
|
+
- Use SWR for automatic request deduplication
|
|
63
|
+
- Defer state reads to usage point
|
|
64
|
+
- Use lazy state initialization for expensive values
|
|
65
|
+
- Use derived state subscriptions
|
|
66
|
+
- Apply `startTransition` for non-urgent updates
|
|
67
|
+
|
|
68
|
+
### Rendering Patterns
|
|
69
|
+
|
|
70
|
+
- Animate SVG wrappers, not SVG elements directly
|
|
71
|
+
- Use `content-visibility: auto` for long lists
|
|
72
|
+
- Prevent hydration mismatch with inline scripts
|
|
73
|
+
- Use explicit conditional rendering (`? :` not `&&`)
|
|
74
|
+
|
|
75
|
+
### JavaScript Patterns
|
|
76
|
+
|
|
77
|
+
- Batch DOM CSS changes via classes
|
|
78
|
+
- Build index maps for repeated lookups
|
|
79
|
+
- Cache repeated function calls
|
|
80
|
+
- Use `toSorted()` instead of `sort()` for immutability
|
|
81
|
+
- Early length check for array comparisons
|
|
82
|
+
|
|
83
|
+
## References
|
|
84
|
+
|
|
85
|
+
Full documentation with code examples is available in:
|
|
86
|
+
|
|
87
|
+
- `references/react-performance-guidelines.md` - Complete guide with all patterns
|
|
88
|
+
- `references/rules/` - Individual rule files organized by category
|
|
89
|
+
|
|
90
|
+
To look up a specific pattern, grep the rules directory:
|
|
91
|
+
```
|
|
92
|
+
grep -l "suspense" references/rules/
|
|
93
|
+
grep -l "barrel" references/rules/
|
|
94
|
+
grep -l "swr" references/rules/
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Rule Categories in `references/rules/`
|
|
98
|
+
|
|
99
|
+
- `async-*` - Waterfall elimination patterns
|
|
100
|
+
- `bundle-*` - Bundle size optimization
|
|
101
|
+
- `server-*` - Server-side performance
|
|
102
|
+
- `client-*` - Client-side data fetching
|
|
103
|
+
- `rerender-*` - Re-render optimization
|
|
104
|
+
- `rendering-*` - DOM rendering performance
|
|
105
|
+
- `js-*` - JavaScript micro-optimizations
|
|
106
|
+
- `advanced-*` - Advanced patterns
|
package/templates/skills/design/react-best-practices/references/react-performance-guidelines.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# React Best Practices
|
|
2
|
+
|
|
3
|
+
**Version 0.1.0**
|
|
4
|
+
Vercel Engineering
|
|
5
|
+
January 2026
|
|
6
|
+
|
|
7
|
+
> **Note:**
|
|
8
|
+
> This document is mainly for agents and LLMs to follow when maintaining,
|
|
9
|
+
> generating, or refactoring React and Next.js codebases. Humans
|
|
10
|
+
> may also find it useful, but guidance here is optimized for automation
|
|
11
|
+
> and consistency by AI-assisted workflows.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Abstract
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Table of Contents
|
|
22
|
+
|
|
23
|
+
1. [Eliminating Waterfalls](#1-eliminating-waterfalls) — **CRITICAL**
|
|
24
|
+
2. [Bundle Size Optimization](#2-bundle-size-optimization) — **CRITICAL**
|
|
25
|
+
3. [Server-Side Performance](#3-server-side-performance) — **HIGH**
|
|
26
|
+
4. [Client-Side Data Fetching](#4-client-side-data-fetching) — **MEDIUM-HIGH**
|
|
27
|
+
5. [Re-render Optimization](#5-re-render-optimization) — **MEDIUM**
|
|
28
|
+
6. [Rendering Performance](#6-rendering-performance) — **MEDIUM**
|
|
29
|
+
7. [JavaScript Performance](#7-javascript-performance) — **LOW-MEDIUM**
|
|
30
|
+
8. [Advanced Patterns](#8-advanced-patterns) — **LOW**
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 1. Eliminating Waterfalls
|
|
35
|
+
|
|
36
|
+
**Impact: CRITICAL**
|
|
37
|
+
|
|
38
|
+
Waterfalls are the #1 performance killer. Each sequential await adds full network latency.
|
|
39
|
+
|
|
40
|
+
### Key Patterns:
|
|
41
|
+
|
|
42
|
+
- **Defer await until needed** - Move `await` into branches where data is actually used
|
|
43
|
+
- **Use Promise.all()** - For independent async operations
|
|
44
|
+
- **Start promises early, await late** - Begin fetches immediately, await when needed
|
|
45
|
+
- **Use Suspense boundaries** - Stream content to show wrapper UI faster
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 2. Bundle Size Optimization
|
|
50
|
+
|
|
51
|
+
**Impact: CRITICAL**
|
|
52
|
+
|
|
53
|
+
### Key Patterns:
|
|
54
|
+
|
|
55
|
+
- **Avoid barrel file imports** - Import directly from source files
|
|
56
|
+
- **Use dynamic imports** - For heavy components not needed on initial render
|
|
57
|
+
- **Defer third-party libraries** - Load analytics, logging after hydration
|
|
58
|
+
- **Preload on user intent** - Load bundles on hover/focus before click
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 3. Server-Side Performance
|
|
63
|
+
|
|
64
|
+
**Impact: HIGH**
|
|
65
|
+
|
|
66
|
+
### Key Patterns:
|
|
67
|
+
|
|
68
|
+
- **React.cache()** - Per-request deduplication
|
|
69
|
+
- **LRU cache** - Cross-request caching
|
|
70
|
+
- **Minimize serialization** - Only pass needed fields across RSC boundaries
|
|
71
|
+
- **Parallel component composition** - Restructure for concurrent data fetching
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 4. Client-Side Data Fetching
|
|
76
|
+
|
|
77
|
+
**Impact: MEDIUM-HIGH**
|
|
78
|
+
|
|
79
|
+
### Key Patterns:
|
|
80
|
+
|
|
81
|
+
- **SWR** - Automatic request deduplication and caching
|
|
82
|
+
- **useSWRSubscription** - Share global event listeners
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 5. Re-render Optimization
|
|
87
|
+
|
|
88
|
+
**Impact: MEDIUM**
|
|
89
|
+
|
|
90
|
+
### Key Patterns:
|
|
91
|
+
|
|
92
|
+
- **Defer state reads** - Read searchParams/localStorage in callbacks, not subscriptions
|
|
93
|
+
- **Extract memoized components** - Enable early returns before computation
|
|
94
|
+
- **Narrow effect dependencies** - Use primitives instead of objects
|
|
95
|
+
- **Lazy state initialization** - Pass functions to useState for expensive values
|
|
96
|
+
- **startTransition** - Mark non-urgent updates
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 6. Rendering Performance
|
|
101
|
+
|
|
102
|
+
**Impact: MEDIUM**
|
|
103
|
+
|
|
104
|
+
### Key Patterns:
|
|
105
|
+
|
|
106
|
+
- **Animate SVG wrappers** - Not SVG elements directly
|
|
107
|
+
- **content-visibility: auto** - Defer off-screen rendering
|
|
108
|
+
- **Hoist static JSX** - Avoid recreating elements
|
|
109
|
+
- **Prevent hydration mismatch** - Use inline scripts for client-only data
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 7. JavaScript Performance
|
|
114
|
+
|
|
115
|
+
**Impact: LOW-MEDIUM**
|
|
116
|
+
|
|
117
|
+
### Key Patterns:
|
|
118
|
+
|
|
119
|
+
- **Batch DOM CSS changes** - Via classes or cssText
|
|
120
|
+
- **Build index maps** - For repeated lookups
|
|
121
|
+
- **Cache function results** - Module-level Map
|
|
122
|
+
- **toSorted() over sort()** - Immutable array operations
|
|
123
|
+
- **Early length check** - Before expensive array comparisons
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 8. Advanced Patterns
|
|
128
|
+
|
|
129
|
+
**Impact: LOW**
|
|
130
|
+
|
|
131
|
+
### Key Patterns:
|
|
132
|
+
|
|
133
|
+
- **Store handlers in refs** - Stable subscriptions
|
|
134
|
+
- **useLatest** - Access latest values without dependency changes
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## References
|
|
139
|
+
|
|
140
|
+
1. [https://react.dev](https://react.dev)
|
|
141
|
+
2. [https://nextjs.org](https://nextjs.org)
|
|
142
|
+
3. [https://swr.vercel.app](https://swr.vercel.app)
|
|
143
|
+
4. [https://vercel.com/blog/how-we-optimized-package-imports-in-next-js](https://vercel.com/blog/how-we-optimized-package-imports-in-next-js)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# SEO Review
|
|
2
|
+
|
|
3
|
+
Audit pages for SEO best practices.
|
|
4
|
+
|
|
5
|
+
## Checklist
|
|
6
|
+
|
|
7
|
+
### Meta Tags (Critical)
|
|
8
|
+
|
|
9
|
+
- [ ] `<title>` exists, 50-60 characters
|
|
10
|
+
- [ ] `<meta name="description">` exists, 150-160 characters
|
|
11
|
+
- [ ] `<meta name="viewport">` set correctly
|
|
12
|
+
- [ ] `<link rel="canonical">` for duplicate content prevention
|
|
13
|
+
- [ ] Language declared: `<html lang="en">`
|
|
14
|
+
|
|
15
|
+
### Open Graph (Social)
|
|
16
|
+
|
|
17
|
+
- [ ] `og:title` — same or variant of title
|
|
18
|
+
- [ ] `og:description` — same or variant of meta description
|
|
19
|
+
- [ ] `og:image` — 1200×630px minimum
|
|
20
|
+
- [ ] `og:url` — canonical URL
|
|
21
|
+
- [ ] `og:type` — website, article, product, etc.
|
|
22
|
+
|
|
23
|
+
### Twitter Cards
|
|
24
|
+
|
|
25
|
+
- [ ] `twitter:card` — summary_large_image recommended
|
|
26
|
+
- [ ] `twitter:title`
|
|
27
|
+
- [ ] `twitter:description`
|
|
28
|
+
- [ ] `twitter:image`
|
|
29
|
+
|
|
30
|
+
### Headings
|
|
31
|
+
|
|
32
|
+
- [ ] Single `<h1>` per page
|
|
33
|
+
- [ ] Logical hierarchy: h1 → h2 → h3 (no skipping)
|
|
34
|
+
- [ ] Headings describe content (not styled text)
|
|
35
|
+
|
|
36
|
+
### Images
|
|
37
|
+
|
|
38
|
+
- [ ] All `<img>` have `alt` attributes
|
|
39
|
+
- [ ] Alt text is descriptive, not "image" or filename
|
|
40
|
+
- [ ] Decorative images use `alt=""`
|
|
41
|
+
- [ ] Images have width/height to prevent layout shift
|
|
42
|
+
|
|
43
|
+
### Links
|
|
44
|
+
|
|
45
|
+
- [ ] Descriptive link text (not "click here")
|
|
46
|
+
- [ ] External links have `rel="noopener noreferrer"`
|
|
47
|
+
- [ ] No broken links
|
|
48
|
+
- [ ] Important pages within 3 clicks of homepage
|
|
49
|
+
|
|
50
|
+
### Performance (SEO Impact)
|
|
51
|
+
|
|
52
|
+
- [ ] Core Web Vitals passing
|
|
53
|
+
- [ ] No render-blocking resources
|
|
54
|
+
- [ ] Images optimized (WebP, lazy loading)
|
|
55
|
+
- [ ] Fonts preloaded
|
|
56
|
+
|
|
57
|
+
### Indexing
|
|
58
|
+
|
|
59
|
+
- [ ] `robots.txt` allows crawling
|
|
60
|
+
- [ ] `sitemap.xml` exists and is valid
|
|
61
|
+
- [ ] No `noindex` on important pages
|
|
62
|
+
- [ ] JSON-LD structured data present
|
|
63
|
+
|
|
64
|
+
## Review Process
|
|
65
|
+
|
|
66
|
+
1. Read `index.html` for meta tags
|
|
67
|
+
2. Scan page components for heading structure
|
|
68
|
+
3. Check images for alt text
|
|
69
|
+
4. Verify Open Graph tags
|
|
70
|
+
5. Check for sitemap.xml and robots.txt
|
|
71
|
+
6. Report findings with line numbers
|
|
72
|
+
|
|
73
|
+
## Output Format
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
SEO REVIEW: [page name]
|
|
77
|
+
═══════════════════════
|
|
78
|
+
|
|
79
|
+
CRITICAL
|
|
80
|
+
────────
|
|
81
|
+
✗ Missing meta description
|
|
82
|
+
Fix: Add <meta name="description" content="...">
|
|
83
|
+
|
|
84
|
+
WARNINGS
|
|
85
|
+
────────
|
|
86
|
+
⚠ Title too long (72 chars, max 60)
|
|
87
|
+
Current: "Very Long Title That Goes On..."
|
|
88
|
+
|
|
89
|
+
PASSED
|
|
90
|
+
──────
|
|
91
|
+
✓ Single h1 element
|
|
92
|
+
✓ All images have alt text
|
|
93
|
+
✓ Open Graph tags present
|
|
94
|
+
|
|
95
|
+
Score: 7/10
|
|
96
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Sitemap Generator
|
|
2
|
+
|
|
3
|
+
Generate XML sitemaps for static and dynamic routes.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
- Before deploying to production
|
|
8
|
+
- After adding new pages/routes
|
|
9
|
+
- When setting up SEO
|
|
10
|
+
|
|
11
|
+
## Output Format
|
|
12
|
+
|
|
13
|
+
Generate `public/sitemap.xml`:
|
|
14
|
+
|
|
15
|
+
```xml
|
|
16
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
17
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
18
|
+
<url>
|
|
19
|
+
<loc>https://example.com/</loc>
|
|
20
|
+
<lastmod>2024-01-01</lastmod>
|
|
21
|
+
<changefreq>weekly</changefreq>
|
|
22
|
+
<priority>1.0</priority>
|
|
23
|
+
</url>
|
|
24
|
+
<url>
|
|
25
|
+
<loc>https://example.com/about</loc>
|
|
26
|
+
<lastmod>2024-01-01</lastmod>
|
|
27
|
+
<changefreq>monthly</changefreq>
|
|
28
|
+
<priority>0.8</priority>
|
|
29
|
+
</url>
|
|
30
|
+
</urlset>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Priority Guidelines
|
|
34
|
+
|
|
35
|
+
| Page Type | Priority | Change Frequency |
|
|
36
|
+
|-----------|----------|------------------|
|
|
37
|
+
| Homepage | 1.0 | weekly |
|
|
38
|
+
| Main sections | 0.8 | weekly |
|
|
39
|
+
| Blog posts | 0.6 | monthly |
|
|
40
|
+
| Legal pages | 0.3 | yearly |
|
|
41
|
+
|
|
42
|
+
## Steps
|
|
43
|
+
|
|
44
|
+
1. Scan `src/pages/` for route components
|
|
45
|
+
2. Check `src/App.tsx` for route definitions
|
|
46
|
+
3. Extract all public routes (exclude auth-protected)
|
|
47
|
+
4. Generate sitemap.xml with today's date
|
|
48
|
+
5. Create `public/robots.txt` if missing:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
User-agent: *
|
|
52
|
+
Allow: /
|
|
53
|
+
Sitemap: https://example.com/sitemap.xml
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Dynamic Routes
|
|
57
|
+
|
|
58
|
+
For dynamic routes like `/blog/:slug`, either:
|
|
59
|
+
- Fetch content list from CMS/API
|
|
60
|
+
- Read from `src/data/` files
|
|
61
|
+
- Ask user for URL list
|
|
62
|
+
|
|
63
|
+
## Validation
|
|
64
|
+
|
|
65
|
+
After generation, validate at:
|
|
66
|
+
- https://www.xml-sitemaps.com/validate-xml-sitemap.html
|