claude-cli-advanced-starter-pack 1.0.16 → 1.8.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/OVERVIEW.md +5 -1
- package/README.md +241 -132
- package/bin/gtask.js +53 -0
- package/package.json +1 -1
- package/src/cli/menu.js +27 -0
- package/src/commands/explore-mcp/mcp-registry.js +99 -0
- package/src/commands/init.js +309 -80
- package/src/commands/install-panel-hook.js +108 -0
- package/src/commands/install-scripts.js +232 -0
- package/src/commands/install-skill.js +220 -0
- package/src/commands/panel.js +297 -0
- package/src/commands/setup-wizard.js +4 -3
- package/src/commands/test-setup.js +4 -5
- package/src/data/releases.json +209 -0
- package/src/panel/queue.js +188 -0
- package/templates/commands/ask-claude.template.md +118 -0
- package/templates/commands/ccasp-panel.template.md +72 -0
- package/templates/commands/ccasp-setup.template.md +470 -79
- package/templates/commands/create-smoke-test.template.md +186 -0
- package/templates/commands/project-impl.template.md +9 -113
- package/templates/commands/refactor-check.template.md +112 -0
- package/templates/commands/refactor-cleanup.template.md +144 -0
- package/templates/commands/refactor-prep.template.md +192 -0
- package/templates/docs/AI_ARCHITECTURE_CONSTITUTION.template.md +198 -0
- package/templates/docs/DETAILED_GOTCHAS.template.md +347 -0
- package/templates/docs/PHASE-DEV-CHECKLIST.template.md +241 -0
- package/templates/docs/PROGRESS_JSON_TEMPLATE.json +117 -0
- package/templates/docs/background-agent.template.md +264 -0
- package/templates/hooks/autonomous-decision-logger.template.js +207 -0
- package/templates/hooks/branch-merge-checker.template.js +272 -0
- package/templates/hooks/context-injector.template.js +261 -0
- package/templates/hooks/git-commit-tracker.template.js +267 -0
- package/templates/hooks/happy-mode-detector.template.js +214 -0
- package/templates/hooks/happy-title-generator.template.js +260 -0
- package/templates/hooks/issue-completion-detector.template.js +205 -0
- package/templates/hooks/panel-queue-reader.template.js +83 -0
- package/templates/hooks/phase-validation-gates.template.js +307 -0
- package/templates/hooks/session-id-generator.template.js +236 -0
- package/templates/hooks/token-budget-loader.template.js +234 -0
- package/templates/hooks/token-usage-monitor.template.js +193 -0
- package/templates/hooks/tool-output-cacher.template.js +219 -0
- package/templates/patterns/README.md +129 -0
- package/templates/patterns/l1-l2-orchestration.md +189 -0
- package/templates/patterns/multi-phase-orchestration.md +258 -0
- package/templates/patterns/two-tier-query-pipeline.md +192 -0
- package/templates/scripts/README.md +109 -0
- package/templates/scripts/analyze-delegation-log.js +299 -0
- package/templates/scripts/autonomous-decision-logger.js +277 -0
- package/templates/scripts/git-history-analyzer.py +269 -0
- package/templates/scripts/phase-validation-gates.js +307 -0
- package/templates/scripts/poll-deployment-status.js +260 -0
- package/templates/scripts/roadmap-scanner.js +263 -0
- package/templates/scripts/validate-deployment.js +293 -0
- package/templates/skills/agent-creator/skill.json +18 -0
- package/templates/skills/agent-creator/skill.md +335 -0
- package/templates/skills/hook-creator/skill.json +18 -0
- package/templates/skills/hook-creator/skill.md +318 -0
- package/templates/skills/panel/skill.json +18 -0
- package/templates/skills/panel/skill.md +90 -0
- package/templates/skills/rag-agent-creator/skill.json +18 -0
- package/templates/skills/rag-agent-creator/skill.md +307 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Pre-refactoring safety checklist - ensure safe refactoring conditions
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Refactor Prep
|
|
6
|
+
|
|
7
|
+
Comprehensive safety checklist before starting any refactoring work. Ensures you can safely make changes and recover if needed.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
/refactor-prep
|
|
13
|
+
/refactor-prep --scope src/components
|
|
14
|
+
/refactor-prep --quick # Abbreviated checklist
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Safety Checklist
|
|
18
|
+
|
|
19
|
+
### 1. Git Status
|
|
20
|
+
- [ ] Working directory is clean
|
|
21
|
+
- [ ] On correct branch (not main/master)
|
|
22
|
+
- [ ] Remote is up to date
|
|
23
|
+
|
|
24
|
+
### 2. Test Coverage
|
|
25
|
+
- [ ] All tests passing
|
|
26
|
+
- [ ] Affected code has test coverage
|
|
27
|
+
- [ ] E2E tests available for critical paths
|
|
28
|
+
|
|
29
|
+
### 3. Backup Points
|
|
30
|
+
- [ ] Create rollback commit/tag
|
|
31
|
+
- [ ] Document current behavior
|
|
32
|
+
- [ ] Screenshot/record current UI state
|
|
33
|
+
|
|
34
|
+
### 4. Dependencies
|
|
35
|
+
- [ ] No pending dependency updates
|
|
36
|
+
- [ ] Lock file is committed
|
|
37
|
+
- [ ] Build succeeds
|
|
38
|
+
|
|
39
|
+
### 5. Documentation
|
|
40
|
+
- [ ] Refactoring scope defined
|
|
41
|
+
- [ ] Breaking changes identified
|
|
42
|
+
- [ ] Migration plan documented
|
|
43
|
+
|
|
44
|
+
## Implementation
|
|
45
|
+
|
|
46
|
+
### Step 1: Git Safety Check
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Check working directory
|
|
50
|
+
git status
|
|
51
|
+
|
|
52
|
+
# Verify branch
|
|
53
|
+
git branch --show-current
|
|
54
|
+
|
|
55
|
+
# Check sync with remote
|
|
56
|
+
git fetch && git status -uno
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Step 2: Test Status
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Run full test suite
|
|
63
|
+
npm test
|
|
64
|
+
|
|
65
|
+
# Check coverage for affected files
|
|
66
|
+
npm run coverage -- --collectCoverageFrom="src/components/**"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Step 3: Create Rollback Point
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Tag current state
|
|
73
|
+
git tag pre-refactor-$(date +%Y%m%d)
|
|
74
|
+
|
|
75
|
+
# Create backup branch
|
|
76
|
+
git branch backup/pre-refactor-$(date +%Y%m%d)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Step 4: Build Verification
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Clean build
|
|
83
|
+
rm -rf node_modules/.cache dist/
|
|
84
|
+
npm run build
|
|
85
|
+
|
|
86
|
+
# Type check
|
|
87
|
+
npm run typecheck
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Output Report
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
Refactor Prep Checklist
|
|
94
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
95
|
+
|
|
96
|
+
Git Status:
|
|
97
|
+
✅ Working directory clean
|
|
98
|
+
✅ On branch: feature/refactor-components
|
|
99
|
+
✅ Up to date with origin
|
|
100
|
+
|
|
101
|
+
Tests:
|
|
102
|
+
✅ All 145 tests passing
|
|
103
|
+
⚠️ Affected files have 67% coverage (target: 80%)
|
|
104
|
+
✅ E2E tests passing
|
|
105
|
+
|
|
106
|
+
Backup:
|
|
107
|
+
✅ Created tag: pre-refactor-20260130
|
|
108
|
+
✅ Created branch: backup/pre-refactor-20260130
|
|
109
|
+
|
|
110
|
+
Build:
|
|
111
|
+
✅ TypeScript: No errors
|
|
112
|
+
✅ Build: Success
|
|
113
|
+
|
|
114
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
115
|
+
Ready Score: 95%
|
|
116
|
+
|
|
117
|
+
Recommendations:
|
|
118
|
+
1. Consider adding tests for src/components/Modal.tsx (0% coverage)
|
|
119
|
+
2. Document expected behavior changes
|
|
120
|
+
|
|
121
|
+
Proceed with refactoring? [Y/N]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Scope Analysis
|
|
125
|
+
|
|
126
|
+
When `--scope` is provided:
|
|
127
|
+
|
|
128
|
+
1. **Identify Files** - List all files in scope
|
|
129
|
+
2. **Find Dependencies** - Map imports and exports
|
|
130
|
+
3. **Calculate Impact** - Estimate affected components
|
|
131
|
+
4. **Suggest Order** - Recommend refactoring sequence
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
Scope Analysis: src/components/
|
|
135
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
136
|
+
|
|
137
|
+
Files in Scope: 23
|
|
138
|
+
Direct Dependencies: 45
|
|
139
|
+
Potential Impact: 67 files
|
|
140
|
+
|
|
141
|
+
Dependency Graph:
|
|
142
|
+
Button.tsx
|
|
143
|
+
├── Used by: 12 components
|
|
144
|
+
├── Tests: 3 files
|
|
145
|
+
└── Risk: Medium
|
|
146
|
+
|
|
147
|
+
Modal.tsx
|
|
148
|
+
├── Used by: 8 components
|
|
149
|
+
├── Tests: 0 files
|
|
150
|
+
└── Risk: High (no tests!)
|
|
151
|
+
|
|
152
|
+
Recommended Order:
|
|
153
|
+
1. Add tests for Modal.tsx (reduce risk)
|
|
154
|
+
2. Refactor leaf components first (Button, Icon)
|
|
155
|
+
3. Work up to container components
|
|
156
|
+
4. Update integration tests last
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Quick Mode
|
|
160
|
+
|
|
161
|
+
Use `--quick` for abbreviated checklist:
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
Quick Refactor Prep
|
|
165
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
166
|
+
✅ Git clean
|
|
167
|
+
✅ Tests passing
|
|
168
|
+
✅ Backup created: pre-refactor-20260130
|
|
169
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
170
|
+
Ready to refactor!
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Recovery Commands
|
|
174
|
+
|
|
175
|
+
If refactoring goes wrong:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Return to pre-refactor state
|
|
179
|
+
git checkout pre-refactor-20260130
|
|
180
|
+
|
|
181
|
+
# Or restore from backup branch
|
|
182
|
+
git checkout backup/pre-refactor-20260130
|
|
183
|
+
|
|
184
|
+
# Delete failed changes
|
|
185
|
+
git reset --hard backup/pre-refactor-20260130
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Related Commands
|
|
189
|
+
|
|
190
|
+
- `/refactor-check` - Pre-commit quality gate
|
|
191
|
+
- `/refactor-cleanup` - Auto-fix common issues
|
|
192
|
+
- `/refactor-analyze` - Deep code analysis
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# {{project.name}} - AI Architecture Constitution
|
|
2
|
+
|
|
3
|
+
**Version**: 1.0.0
|
|
4
|
+
**Created**: {{date}}
|
|
5
|
+
**Status**: Active
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
This document defines non-negotiable rules that Claude must follow when working on this project. These laws protect data integrity, prevent architectural violations, and ensure code quality.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Boot Sequence (MANDATORY)
|
|
14
|
+
|
|
15
|
+
Before responding to any request, Claude must:
|
|
16
|
+
|
|
17
|
+
1. Load this constitution file
|
|
18
|
+
2. Enforce all laws - refuse or auto-refactor violations
|
|
19
|
+
3. Reference project-specific documentation as needed
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Law 1: Data Storage
|
|
24
|
+
|
|
25
|
+
**CRITICAL: All user data MUST follow the designated storage pattern.**
|
|
26
|
+
|
|
27
|
+
| Data Type | Storage | Status |
|
|
28
|
+
|-----------|---------|--------|
|
|
29
|
+
| User preferences | Designated database | Required |
|
|
30
|
+
| Session data | Designated storage | Required |
|
|
31
|
+
| Configuration | Config files | Allowed |
|
|
32
|
+
| Cached data | Cache directory | Temporary only |
|
|
33
|
+
|
|
34
|
+
### Forbidden Patterns
|
|
35
|
+
|
|
36
|
+
- Storing user data in flat files when database is available
|
|
37
|
+
- Mixing storage approaches inconsistently
|
|
38
|
+
- Bypassing repository/service layer for direct database access
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Law 2: Architecture Patterns
|
|
43
|
+
|
|
44
|
+
### Required Patterns
|
|
45
|
+
|
|
46
|
+
| Pattern | Rule |
|
|
47
|
+
|---------|------|
|
|
48
|
+
| **Repository** | All database access via repository layer |
|
|
49
|
+
| **Service** | Business logic in service layer |
|
|
50
|
+
| **Controller** | HTTP handling only in controller layer |
|
|
51
|
+
| **Component** | UI logic in component layer |
|
|
52
|
+
|
|
53
|
+
### Forbidden Patterns
|
|
54
|
+
|
|
55
|
+
- Direct database queries in controllers/components
|
|
56
|
+
- Business logic in UI components
|
|
57
|
+
- Cross-layer dependencies that bypass layers
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Law 3: Code Quality
|
|
62
|
+
|
|
63
|
+
### Must Do
|
|
64
|
+
|
|
65
|
+
1. **Type Safety** - Use TypeScript/type hints strictly
|
|
66
|
+
2. **Error Handling** - All async operations must have error handling
|
|
67
|
+
3. **Testing** - New features require test coverage
|
|
68
|
+
4. **Documentation** - Public APIs must be documented
|
|
69
|
+
|
|
70
|
+
### Must Avoid
|
|
71
|
+
|
|
72
|
+
1. **Any/unknown types** - Explicit types required
|
|
73
|
+
2. **Silent failures** - All errors must be logged/handled
|
|
74
|
+
3. **Magic strings** - Use constants/enums
|
|
75
|
+
4. **Nested callbacks** - Use async/await
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Law 4: Security
|
|
80
|
+
|
|
81
|
+
### Non-Negotiable
|
|
82
|
+
|
|
83
|
+
1. **No secrets in code** - Use environment variables
|
|
84
|
+
2. **No hardcoded credentials** - Use secret management
|
|
85
|
+
3. **Validate all inputs** - Never trust user input
|
|
86
|
+
4. **Sanitize outputs** - Prevent XSS/injection
|
|
87
|
+
|
|
88
|
+
### Protected Files
|
|
89
|
+
|
|
90
|
+
- `.env` files - Never commit
|
|
91
|
+
- Credential files - Never read content aloud
|
|
92
|
+
- Private keys - Never expose
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Law 5: Performance
|
|
97
|
+
|
|
98
|
+
### Required
|
|
99
|
+
|
|
100
|
+
1. **Lazy loading** - Load resources on demand
|
|
101
|
+
2. **Pagination** - Never load unlimited records
|
|
102
|
+
3. **Caching** - Cache expensive operations
|
|
103
|
+
4. **Async operations** - Don't block main thread
|
|
104
|
+
|
|
105
|
+
### Thresholds
|
|
106
|
+
|
|
107
|
+
| Metric | Maximum |
|
|
108
|
+
|--------|---------|
|
|
109
|
+
| API response | 500ms |
|
|
110
|
+
| Page load | 3s |
|
|
111
|
+
| Database query | 100ms |
|
|
112
|
+
| Bundle size | 500KB |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Law 6: Git Workflow
|
|
117
|
+
|
|
118
|
+
### Commit Standards
|
|
119
|
+
|
|
120
|
+
1. **Message format**: `type(scope): description`
|
|
121
|
+
2. **Types**: feat, fix, refactor, docs, test, chore
|
|
122
|
+
3. **Atomic commits**: One logical change per commit
|
|
123
|
+
|
|
124
|
+
### Forbidden
|
|
125
|
+
|
|
126
|
+
- Committing to main/master directly (without review)
|
|
127
|
+
- Force pushing to shared branches
|
|
128
|
+
- Committing sensitive files
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Law 7: Dependency Management
|
|
133
|
+
|
|
134
|
+
### Rules
|
|
135
|
+
|
|
136
|
+
1. **Lock files** - Always commit package-lock.json/yarn.lock
|
|
137
|
+
2. **Version pinning** - Use exact versions in production
|
|
138
|
+
3. **Security updates** - Apply promptly
|
|
139
|
+
4. **Minimal dependencies** - Avoid bloat
|
|
140
|
+
|
|
141
|
+
### Forbidden
|
|
142
|
+
|
|
143
|
+
- Installing deprecated packages
|
|
144
|
+
- Using packages with known vulnerabilities
|
|
145
|
+
- Adding dependencies without justification
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Enforcement
|
|
150
|
+
|
|
151
|
+
### Violation Response
|
|
152
|
+
|
|
153
|
+
When a violation is detected:
|
|
154
|
+
|
|
155
|
+
1. **Stop** - Do not proceed with the violating action
|
|
156
|
+
2. **Explain** - Describe why this violates the constitution
|
|
157
|
+
3. **Suggest** - Provide compliant alternative
|
|
158
|
+
4. **Refactor** - Auto-fix if possible
|
|
159
|
+
|
|
160
|
+
### Auto-Refactor Triggers
|
|
161
|
+
|
|
162
|
+
Claude will automatically refactor when:
|
|
163
|
+
|
|
164
|
+
- Direct database access detected outside repository
|
|
165
|
+
- Hardcoded secrets detected
|
|
166
|
+
- Missing error handling detected
|
|
167
|
+
- Type safety violations detected
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Amendment Process
|
|
172
|
+
|
|
173
|
+
To modify this constitution:
|
|
174
|
+
|
|
175
|
+
1. Create a proposal document
|
|
176
|
+
2. Review impact on existing code
|
|
177
|
+
3. Update this file with version bump
|
|
178
|
+
4. Apply changes to codebase
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Quick Reference
|
|
183
|
+
|
|
184
|
+
### Always Do
|
|
185
|
+
- Use repository pattern for data access
|
|
186
|
+
- Handle all errors explicitly
|
|
187
|
+
- Use environment variables for config
|
|
188
|
+
- Write tests for new features
|
|
189
|
+
|
|
190
|
+
### Never Do
|
|
191
|
+
- Store secrets in code
|
|
192
|
+
- Bypass architectural layers
|
|
193
|
+
- Commit to main directly
|
|
194
|
+
- Use any/unknown types
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
*This constitution is enforced by Claude Code for {{project.name}}*
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# {{project.name}} - Detailed Gotchas
|
|
2
|
+
|
|
3
|
+
Problem-solution patterns learned from development experience. Reference this before making changes.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick Reference
|
|
8
|
+
|
|
9
|
+
| Category | Common Issue | Solution |
|
|
10
|
+
|----------|--------------|----------|
|
|
11
|
+
| Async | Race conditions | Use proper await/locks |
|
|
12
|
+
| State | Stale data | Invalidate caches properly |
|
|
13
|
+
| UI | Flash of content | Add loading states |
|
|
14
|
+
| API | Timeout errors | Implement retry logic |
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Async Operations
|
|
19
|
+
|
|
20
|
+
### Problem: Race Conditions in State Updates
|
|
21
|
+
|
|
22
|
+
**Symptoms:**
|
|
23
|
+
- Intermittent bugs
|
|
24
|
+
- Inconsistent state
|
|
25
|
+
- "It works sometimes"
|
|
26
|
+
|
|
27
|
+
**Root Cause:**
|
|
28
|
+
Multiple async operations completing out of order.
|
|
29
|
+
|
|
30
|
+
**Solution:**
|
|
31
|
+
```typescript
|
|
32
|
+
// BAD - race condition
|
|
33
|
+
async function fetchBoth() {
|
|
34
|
+
fetchA().then(setA);
|
|
35
|
+
fetchB().then(setB);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// GOOD - controlled ordering
|
|
39
|
+
async function fetchBoth() {
|
|
40
|
+
const [a, b] = await Promise.all([fetchA(), fetchB()]);
|
|
41
|
+
setA(a);
|
|
42
|
+
setB(b);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Problem: Unhandled Promise Rejections
|
|
47
|
+
|
|
48
|
+
**Symptoms:**
|
|
49
|
+
- Silent failures
|
|
50
|
+
- Incomplete operations
|
|
51
|
+
- No error messages
|
|
52
|
+
|
|
53
|
+
**Solution:**
|
|
54
|
+
```typescript
|
|
55
|
+
// BAD - no error handling
|
|
56
|
+
fetchData().then(process);
|
|
57
|
+
|
|
58
|
+
// GOOD - explicit error handling
|
|
59
|
+
fetchData()
|
|
60
|
+
.then(process)
|
|
61
|
+
.catch(error => {
|
|
62
|
+
console.error('Fetch failed:', error);
|
|
63
|
+
showUserError('Unable to load data');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// BETTER - async/await with try/catch
|
|
67
|
+
try {
|
|
68
|
+
const data = await fetchData();
|
|
69
|
+
process(data);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
handleError(error);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## State Management
|
|
78
|
+
|
|
79
|
+
### Problem: Stale Closure Data
|
|
80
|
+
|
|
81
|
+
**Symptoms:**
|
|
82
|
+
- Event handlers use old values
|
|
83
|
+
- Updates don't reflect current state
|
|
84
|
+
|
|
85
|
+
**Root Cause:**
|
|
86
|
+
Closures capturing stale variable references.
|
|
87
|
+
|
|
88
|
+
**Solution:**
|
|
89
|
+
```typescript
|
|
90
|
+
// BAD - stale closure
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const handler = () => console.log(count);
|
|
93
|
+
window.addEventListener('click', handler);
|
|
94
|
+
}, []); // count will always be initial value
|
|
95
|
+
|
|
96
|
+
// GOOD - use ref for current value
|
|
97
|
+
const countRef = useRef(count);
|
|
98
|
+
countRef.current = count;
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const handler = () => console.log(countRef.current);
|
|
101
|
+
window.addEventListener('click', handler);
|
|
102
|
+
return () => window.removeEventListener('click', handler);
|
|
103
|
+
}, []);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Problem: Cache Invalidation
|
|
107
|
+
|
|
108
|
+
**Symptoms:**
|
|
109
|
+
- Old data displayed after updates
|
|
110
|
+
- Refresh required to see changes
|
|
111
|
+
|
|
112
|
+
**Solution:**
|
|
113
|
+
```typescript
|
|
114
|
+
// Implement proper cache invalidation
|
|
115
|
+
async function updateItem(id, data) {
|
|
116
|
+
await api.update(id, data);
|
|
117
|
+
// Invalidate relevant caches
|
|
118
|
+
cache.delete(`item:${id}`);
|
|
119
|
+
cache.delete('items:list');
|
|
120
|
+
// Refetch if needed
|
|
121
|
+
await refetchQueries(['items']);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## UI Patterns
|
|
128
|
+
|
|
129
|
+
### Problem: Flash of Unstyled/Wrong Content
|
|
130
|
+
|
|
131
|
+
**Symptoms:**
|
|
132
|
+
- Brief flicker on page load
|
|
133
|
+
- Content shifts after hydration
|
|
134
|
+
|
|
135
|
+
**Solution:**
|
|
136
|
+
```typescript
|
|
137
|
+
// Add loading states
|
|
138
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
139
|
+
|
|
140
|
+
if (isLoading) {
|
|
141
|
+
return <Skeleton />;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Use CSS for initial state
|
|
145
|
+
// globals.css
|
|
146
|
+
.app { opacity: 0; }
|
|
147
|
+
.app.loaded { opacity: 1; transition: opacity 0.2s; }
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Problem: Layout Shift
|
|
151
|
+
|
|
152
|
+
**Symptoms:**
|
|
153
|
+
- Content jumps around
|
|
154
|
+
- Poor CLS score
|
|
155
|
+
|
|
156
|
+
**Solution:**
|
|
157
|
+
```css
|
|
158
|
+
/* Reserve space for dynamic content */
|
|
159
|
+
.image-container {
|
|
160
|
+
aspect-ratio: 16/9;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.text-content {
|
|
164
|
+
min-height: 100px;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## API Integration
|
|
171
|
+
|
|
172
|
+
### Problem: Timeout Errors
|
|
173
|
+
|
|
174
|
+
**Symptoms:**
|
|
175
|
+
- Requests fail on slow connections
|
|
176
|
+
- Inconsistent availability
|
|
177
|
+
|
|
178
|
+
**Solution:**
|
|
179
|
+
```typescript
|
|
180
|
+
// Implement retry with exponential backoff
|
|
181
|
+
async function fetchWithRetry(url, options = {}, retries = 3) {
|
|
182
|
+
for (let i = 0; i < retries; i++) {
|
|
183
|
+
try {
|
|
184
|
+
const response = await fetch(url, {
|
|
185
|
+
...options,
|
|
186
|
+
timeout: 5000 + (i * 2000) // Increase timeout with each retry
|
|
187
|
+
});
|
|
188
|
+
return response;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (i === retries - 1) throw error;
|
|
191
|
+
await sleep(Math.pow(2, i) * 1000); // Exponential backoff
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Problem: Rate Limiting
|
|
198
|
+
|
|
199
|
+
**Symptoms:**
|
|
200
|
+
- 429 Too Many Requests
|
|
201
|
+
- API blocks after burst traffic
|
|
202
|
+
|
|
203
|
+
**Solution:**
|
|
204
|
+
```typescript
|
|
205
|
+
// Implement request queue with rate limiting
|
|
206
|
+
const queue = new PQueue({
|
|
207
|
+
concurrency: 2,
|
|
208
|
+
intervalCap: 10,
|
|
209
|
+
interval: 1000
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
async function rateLimitedFetch(url) {
|
|
213
|
+
return queue.add(() => fetch(url));
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Testing
|
|
220
|
+
|
|
221
|
+
### Problem: Flaky Tests
|
|
222
|
+
|
|
223
|
+
**Symptoms:**
|
|
224
|
+
- Tests pass locally, fail in CI
|
|
225
|
+
- Intermittent failures
|
|
226
|
+
|
|
227
|
+
**Common Causes & Solutions:**
|
|
228
|
+
|
|
229
|
+
1. **Timing issues:**
|
|
230
|
+
```typescript
|
|
231
|
+
// BAD
|
|
232
|
+
await click(button);
|
|
233
|
+
expect(modal).toBeVisible();
|
|
234
|
+
|
|
235
|
+
// GOOD
|
|
236
|
+
await click(button);
|
|
237
|
+
await waitFor(() => expect(modal).toBeVisible());
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
2. **Shared state:**
|
|
241
|
+
```typescript
|
|
242
|
+
// Reset state between tests
|
|
243
|
+
beforeEach(() => {
|
|
244
|
+
resetTestDatabase();
|
|
245
|
+
clearMocks();
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
3. **Order dependency:**
|
|
250
|
+
```typescript
|
|
251
|
+
// Make tests independent
|
|
252
|
+
// Don't rely on other tests' side effects
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Performance
|
|
258
|
+
|
|
259
|
+
### Problem: Memory Leaks
|
|
260
|
+
|
|
261
|
+
**Symptoms:**
|
|
262
|
+
- Increasing memory usage
|
|
263
|
+
- Slowdown over time
|
|
264
|
+
|
|
265
|
+
**Common Causes & Solutions:**
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// BAD - event listener not cleaned up
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
window.addEventListener('resize', handleResize);
|
|
271
|
+
}, []);
|
|
272
|
+
|
|
273
|
+
// GOOD - cleanup on unmount
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
window.addEventListener('resize', handleResize);
|
|
276
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
277
|
+
}, []);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Problem: Excessive Re-renders
|
|
281
|
+
|
|
282
|
+
**Symptoms:**
|
|
283
|
+
- Slow UI updates
|
|
284
|
+
- Laggy interactions
|
|
285
|
+
|
|
286
|
+
**Solution:**
|
|
287
|
+
```typescript
|
|
288
|
+
// Use memoization
|
|
289
|
+
const MemoizedComponent = React.memo(ExpensiveComponent);
|
|
290
|
+
|
|
291
|
+
// Memoize callbacks
|
|
292
|
+
const handleClick = useCallback(() => {
|
|
293
|
+
doSomething(id);
|
|
294
|
+
}, [id]);
|
|
295
|
+
|
|
296
|
+
// Memoize computed values
|
|
297
|
+
const sortedItems = useMemo(() => {
|
|
298
|
+
return items.sort((a, b) => a.name.localeCompare(b.name));
|
|
299
|
+
}, [items]);
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Git Workflow
|
|
305
|
+
|
|
306
|
+
### Problem: Merge Conflicts in Lock Files
|
|
307
|
+
|
|
308
|
+
**Solution:**
|
|
309
|
+
```bash
|
|
310
|
+
# Don't try to manually merge lock files
|
|
311
|
+
git checkout --theirs package-lock.json
|
|
312
|
+
npm install
|
|
313
|
+
git add package-lock.json
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Problem: Accidental Commit to Main
|
|
317
|
+
|
|
318
|
+
**Solution:**
|
|
319
|
+
```bash
|
|
320
|
+
# Undo last commit (keep changes)
|
|
321
|
+
git reset --soft HEAD~1
|
|
322
|
+
|
|
323
|
+
# Create new branch with changes
|
|
324
|
+
git checkout -b feature/my-changes
|
|
325
|
+
|
|
326
|
+
# Commit on correct branch
|
|
327
|
+
git commit -m "feat: my changes"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Debugging Checklist
|
|
333
|
+
|
|
334
|
+
When something doesn't work:
|
|
335
|
+
|
|
336
|
+
1. [ ] Check browser console for errors
|
|
337
|
+
2. [ ] Check network tab for failed requests
|
|
338
|
+
3. [ ] Verify environment variables are set
|
|
339
|
+
4. [ ] Clear cache/hard refresh
|
|
340
|
+
5. [ ] Check for type errors
|
|
341
|
+
6. [ ] Review recent changes
|
|
342
|
+
7. [ ] Check dependencies are installed
|
|
343
|
+
8. [ ] Verify database/API is running
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
*Add new gotchas as you encounter them. Future you will thank you.*
|