contextos-agents 1.5.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/.agents/AGENTS.md +421 -0
- package/.agents/adapters/aider/export.js +137 -0
- package/.agents/adapters/claude/export.js +55 -0
- package/.agents/adapters/copilot/export.js +107 -0
- package/.agents/adapters/cursor/export.js +210 -0
- package/.agents/adapters/gemini/export.js +115 -0
- package/.agents/adapters/shared.js +119 -0
- package/.agents/adapters/zed/export.js +111 -0
- package/.agents/core/profiles/backend.yaml +47 -0
- package/.agents/core/profiles/enterprise.yaml +46 -0
- package/.agents/core/profiles/frontend.yaml +46 -0
- package/.agents/core/profiles/hackathon.yaml +45 -0
- package/.agents/core/profiles/mvp.yaml +43 -0
- package/.agents/core/profiles/startup.yaml +48 -0
- package/.agents/core/skills/adapters/EXAMPLES.md +19 -0
- package/.agents/core/skills/adapters/SKILL.md +105 -0
- package/.agents/core/skills/adapters/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/adapters/VALIDATION.json +12 -0
- package/.agents/core/skills/adapters/skill.yaml +10 -0
- package/.agents/core/skills/architecture-diagrams/SKILL.md +108 -0
- package/.agents/core/skills/architecture-diagrams/VALIDATION.json +12 -0
- package/.agents/core/skills/architecture-diagrams/skill.yaml +8 -0
- package/.agents/core/skills/brutalist-design/SKILL.md +150 -0
- package/.agents/core/skills/brutalist-design/VALIDATION.json +12 -0
- package/.agents/core/skills/brutalist-design/skill.yaml +8 -0
- package/.agents/core/skills/context-manager/EXAMPLES.md +19 -0
- package/.agents/core/skills/context-manager/SKILL.md +126 -0
- package/.agents/core/skills/context-manager/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/context-manager/VALIDATION.json +12 -0
- package/.agents/core/skills/context-manager/skill.yaml +10 -0
- package/.agents/core/skills/context-os/EXAMPLES.md +21 -0
- package/.agents/core/skills/context-os/SKILL.md +169 -0
- package/.agents/core/skills/context-os/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/context-os/VALIDATION.json +12 -0
- package/.agents/core/skills/context-os/packs.yaml +59 -0
- package/.agents/core/skills/context-os/references/context-rules.md +68 -0
- package/.agents/core/skills/context-os/references/pipeline.md +119 -0
- package/.agents/core/skills/context-os/references/project-graph.md +103 -0
- package/.agents/core/skills/context-os/rules.yaml +135 -0
- package/.agents/core/skills/context-os/skill.yaml +10 -0
- package/.agents/core/skills/database/EXAMPLES.md +74 -0
- package/.agents/core/skills/database/SKILL.md +101 -0
- package/.agents/core/skills/database/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/database/VALIDATION.json +11 -0
- package/.agents/core/skills/database/skill.yaml +25 -0
- package/.agents/core/skills/ddd/EXAMPLES.md +42 -0
- package/.agents/core/skills/ddd/SKILL.md +247 -0
- package/.agents/core/skills/ddd/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ddd/VALIDATION.json +12 -0
- package/.agents/core/skills/ddd/ddd.md +178 -0
- package/.agents/core/skills/ddd/skill.yaml +10 -0
- package/.agents/core/skills/decisions/EXAMPLES.md +35 -0
- package/.agents/core/skills/decisions/SKILL.md +90 -0
- package/.agents/core/skills/decisions/TROUBLESHOOTING.md +13 -0
- package/.agents/core/skills/decisions/VALIDATION.json +12 -0
- package/.agents/core/skills/decisions/skill.yaml +10 -0
- package/.agents/core/skills/docker/EXAMPLES.md +56 -0
- package/.agents/core/skills/docker/SKILL.md +63 -0
- package/.agents/core/skills/docker/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/docker/VALIDATION.json +11 -0
- package/.agents/core/skills/docker/skill.yaml +23 -0
- package/.agents/core/skills/engineering-workflow/EXAMPLES.md +57 -0
- package/.agents/core/skills/engineering-workflow/SKILL.md +343 -0
- package/.agents/core/skills/engineering-workflow/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/engineering-workflow/VALIDATION.json +12 -0
- package/.agents/core/skills/engineering-workflow/skill.yaml +13 -0
- package/.agents/core/skills/fastapi/EXAMPLES.md +36 -0
- package/.agents/core/skills/fastapi/SKILL.md +148 -0
- package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/fastapi/VALIDATION.json +12 -0
- package/.agents/core/skills/fastapi/fastapi.md +112 -0
- package/.agents/core/skills/fastapi/skill.yaml +10 -0
- package/.agents/core/skills/gemini-precision/SKILL.md +169 -0
- package/.agents/core/skills/gemini-precision/VALIDATION.json +12 -0
- package/.agents/core/skills/gemini-precision/skill.yaml +9 -0
- package/.agents/core/skills/generators/EXAMPLES.md +19 -0
- package/.agents/core/skills/generators/SKILL.md +112 -0
- package/.agents/core/skills/generators/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/generators/VALIDATION.json +12 -0
- package/.agents/core/skills/generators/skill.yaml +10 -0
- package/.agents/core/skills/generators/templates/API.md +77 -0
- package/.agents/core/skills/generators/templates/ARCHITECTURE.md +70 -0
- package/.agents/core/skills/generators/templates/DATABASE.md +42 -0
- package/.agents/core/skills/generators/templates/DECISION.md +46 -0
- package/.agents/core/skills/generators/templates/PRD.md +67 -0
- package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +56 -0
- package/.agents/core/skills/generators/templates/ROADMAP.md +51 -0
- package/.agents/core/skills/generators/templates/TASKS.md +43 -0
- package/.agents/core/skills/generators/templates/UI.md +73 -0
- package/.agents/core/skills/graphify/EXAMPLES.md +73 -0
- package/.agents/core/skills/graphify/SKILL.md +130 -0
- package/.agents/core/skills/graphify/VALIDATION.json +12 -0
- package/.agents/core/skills/graphify/skill.yaml +13 -0
- package/.agents/core/skills/gstack-roles/EXAMPLES.md +23 -0
- package/.agents/core/skills/gstack-roles/SKILL.md +152 -0
- package/.agents/core/skills/gstack-roles/TROUBLESHOOTING.md +13 -0
- package/.agents/core/skills/gstack-roles/VALIDATION.json +12 -0
- package/.agents/core/skills/gstack-roles/skill.yaml +12 -0
- package/.agents/core/skills/impeccable-design/EXAMPLES.md +26 -0
- package/.agents/core/skills/impeccable-design/SKILL.md +201 -0
- package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/impeccable-design/VALIDATION.json +12 -0
- package/.agents/core/skills/impeccable-design/skill.yaml +14 -0
- package/.agents/core/skills/interview-me/SKILL.md +97 -0
- package/.agents/core/skills/interview-me/VALIDATION.json +12 -0
- package/.agents/core/skills/interview-me/skill.yaml +8 -0
- package/.agents/core/skills/microservices/EXAMPLES.md +38 -0
- package/.agents/core/skills/microservices/SKILL.md +164 -0
- package/.agents/core/skills/microservices/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/microservices/VALIDATION.json +12 -0
- package/.agents/core/skills/microservices/microservices.md +119 -0
- package/.agents/core/skills/microservices/skill.yaml +10 -0
- package/.agents/core/skills/minimalist-design/SKILL.md +113 -0
- package/.agents/core/skills/minimalist-design/VALIDATION.json +12 -0
- package/.agents/core/skills/minimalist-design/skill.yaml +8 -0
- package/.agents/core/skills/nestjs/EXAMPLES.md +40 -0
- package/.agents/core/skills/nestjs/SKILL.md +139 -0
- package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/nestjs/VALIDATION.json +12 -0
- package/.agents/core/skills/nestjs/nestjs.md +103 -0
- package/.agents/core/skills/nestjs/skill.yaml +10 -0
- package/.agents/core/skills/nextjs/EXAMPLES.md +40 -0
- package/.agents/core/skills/nextjs/SKILL.md +163 -0
- package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/nextjs/VALIDATION.json +12 -0
- package/.agents/core/skills/nextjs/nextjs.md +67 -0
- package/.agents/core/skills/nextjs/skill.yaml +10 -0
- package/.agents/core/skills/node/EXAMPLES.md +80 -0
- package/.agents/core/skills/node/SKILL.md +128 -0
- package/.agents/core/skills/node/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/node/VALIDATION.json +12 -0
- package/.agents/core/skills/node/node.md +87 -0
- package/.agents/core/skills/node/skill.yaml +10 -0
- package/.agents/core/skills/performance/EXAMPLES.md +30 -0
- package/.agents/core/skills/performance/SKILL.md +75 -0
- package/.agents/core/skills/performance/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/performance/VALIDATION.json +12 -0
- package/.agents/core/skills/performance/performance.md +52 -0
- package/.agents/core/skills/performance/skill.yaml +10 -0
- package/.agents/core/skills/ponytail-mindset/EXAMPLES.md +45 -0
- package/.agents/core/skills/ponytail-mindset/SKILL.md +193 -0
- package/.agents/core/skills/ponytail-mindset/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ponytail-mindset/VALIDATION.json +12 -0
- package/.agents/core/skills/ponytail-mindset/skill.yaml +14 -0
- package/.agents/core/skills/react/EXAMPLES.md +79 -0
- package/.agents/core/skills/react/SKILL.md +132 -0
- package/.agents/core/skills/react/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/react/VALIDATION.json +12 -0
- package/.agents/core/skills/react/react.md +93 -0
- package/.agents/core/skills/react/skill.yaml +10 -0
- package/.agents/core/skills/react-best-practices/SKILL.md +155 -0
- package/.agents/core/skills/react-best-practices/VALIDATION.json +12 -0
- package/.agents/core/skills/react-best-practices/skill.yaml +10 -0
- package/.agents/core/skills/redesign-audit/SKILL.md +117 -0
- package/.agents/core/skills/redesign-audit/VALIDATION.json +12 -0
- package/.agents/core/skills/redesign-audit/skill.yaml +8 -0
- package/.agents/core/skills/security/EXAMPLES.md +64 -0
- package/.agents/core/skills/security/SKILL.md +158 -0
- package/.agents/core/skills/security/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/security/VALIDATION.json +12 -0
- package/.agents/core/skills/security/security.md +106 -0
- package/.agents/core/skills/security/skill.yaml +10 -0
- package/.agents/core/skills/soft-design/SKILL.md +108 -0
- package/.agents/core/skills/soft-design/VALIDATION.json +12 -0
- package/.agents/core/skills/soft-design/skill.yaml +8 -0
- package/.agents/core/skills/state-management/EXAMPLES.md +56 -0
- package/.agents/core/skills/state-management/SKILL.md +48 -0
- package/.agents/core/skills/state-management/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/state-management/VALIDATION.json +11 -0
- package/.agents/core/skills/state-management/skill.yaml +22 -0
- package/.agents/core/skills/subagent-orchestrator/SKILL.md +100 -0
- package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +12 -0
- package/.agents/core/skills/subagent-orchestrator/skill.yaml +8 -0
- package/.agents/core/skills/system-design/EXAMPLES.md +75 -0
- package/.agents/core/skills/system-design/SKILL.md +419 -0
- package/.agents/core/skills/system-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/system-design/VALIDATION.json +12 -0
- package/.agents/core/skills/system-design/skill.yaml +13 -0
- package/.agents/core/skills/system-design/system-design.md +112 -0
- package/.agents/core/skills/testing/EXAMPLES.md +71 -0
- package/.agents/core/skills/testing/SKILL.md +70 -0
- package/.agents/core/skills/testing/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/testing/VALIDATION.json +11 -0
- package/.agents/core/skills/testing/skill.yaml +26 -0
- package/.agents/core/skills/typescript/EXAMPLES.md +64 -0
- package/.agents/core/skills/typescript/SKILL.md +112 -0
- package/.agents/core/skills/typescript/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/typescript/VALIDATION.json +12 -0
- package/.agents/core/skills/typescript/skill.yaml +10 -0
- package/.agents/core/skills/typescript/typescript.md +71 -0
- package/.agents/core/skills/ui-design/EXAMPLES.md +21 -0
- package/.agents/core/skills/ui-design/SKILL.md +124 -0
- package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ui-design/VALIDATION.json +12 -0
- package/.agents/core/skills/ui-design/skill.yaml +10 -0
- package/.agents/core/skills/ui-design/ui.md +88 -0
- package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +62 -0
- package/.agents/core/skills/ui-ux-pro/SKILL.md +375 -0
- package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ui-ux-pro/VALIDATION.json +12 -0
- package/.agents/core/skills/ui-ux-pro/skill.yaml +13 -0
- package/.agents/core/skills/ux-design/EXAMPLES.md +36 -0
- package/.agents/core/skills/ux-design/SKILL.md +116 -0
- package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ux-design/VALIDATION.json +12 -0
- package/.agents/core/skills/ux-design/skill.yaml +10 -0
- package/.agents/core/skills/ux-design/ux.md +80 -0
- package/.agents/core/skills/vercel-optimize/SKILL.md +83 -0
- package/.agents/core/skills/vercel-optimize/VALIDATION.json +12 -0
- package/.agents/core/skills/vercel-optimize/skill.yaml +10 -0
- package/.agents/core/skills/web-accessibility/EXAMPLES.md +39 -0
- package/.agents/core/skills/web-accessibility/SKILL.md +170 -0
- package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/web-accessibility/VALIDATION.json +12 -0
- package/.agents/core/skills/web-accessibility/accessibility.md +63 -0
- package/.agents/core/skills/web-accessibility/skill.yaml +10 -0
- package/.agents/ctx.js +370 -0
- package/.agents/generated/claude/skills/adapters/SKILL.md +126 -0
- package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +101 -0
- package/.agents/generated/claude/skills/brutalist-design/SKILL.md +145 -0
- package/.agents/generated/claude/skills/context-manager/SKILL.md +147 -0
- package/.agents/generated/claude/skills/context-os/SKILL.md +191 -0
- package/.agents/generated/claude/skills/database/SKILL.md +191 -0
- package/.agents/generated/claude/skills/ddd/SKILL.md +305 -0
- package/.agents/generated/claude/skills/decisions/SKILL.md +134 -0
- package/.agents/generated/claude/skills/docker/SKILL.md +135 -0
- package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +414 -0
- package/.agents/generated/claude/skills/fastapi/SKILL.md +200 -0
- package/.agents/generated/claude/skills/gemini-precision/SKILL.md +161 -0
- package/.agents/generated/claude/skills/generators/SKILL.md +133 -0
- package/.agents/generated/claude/skills/graphify/SKILL.md +198 -0
- package/.agents/generated/claude/skills/gstack-roles/SKILL.md +184 -0
- package/.agents/generated/claude/skills/impeccable-design/SKILL.md +241 -0
- package/.agents/generated/claude/skills/interview-me/SKILL.md +90 -0
- package/.agents/generated/claude/skills/microservices/SKILL.md +218 -0
- package/.agents/generated/claude/skills/minimalist-design/SKILL.md +108 -0
- package/.agents/generated/claude/skills/nestjs/SKILL.md +195 -0
- package/.agents/generated/claude/skills/nextjs/SKILL.md +219 -0
- package/.agents/generated/claude/skills/node/SKILL.md +224 -0
- package/.agents/generated/claude/skills/performance/SKILL.md +121 -0
- package/.agents/generated/claude/skills/ponytail-mindset/SKILL.md +252 -0
- package/.agents/generated/claude/skills/react/SKILL.md +227 -0
- package/.agents/generated/claude/skills/react-best-practices/SKILL.md +146 -0
- package/.agents/generated/claude/skills/redesign-audit/SKILL.md +112 -0
- package/.agents/generated/claude/skills/security/SKILL.md +237 -0
- package/.agents/generated/claude/skills/soft-design/SKILL.md +103 -0
- package/.agents/generated/claude/skills/state-management/SKILL.md +120 -0
- package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +93 -0
- package/.agents/generated/claude/skills/system-design/SKILL.md +507 -0
- package/.agents/generated/claude/skills/testing/SKILL.md +157 -0
- package/.agents/generated/claude/skills/typescript/SKILL.md +192 -0
- package/.agents/generated/claude/skills/ui-design/SKILL.md +161 -0
- package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +451 -0
- package/.agents/generated/claude/skills/ux-design/SKILL.md +168 -0
- package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +76 -0
- package/.agents/generated/claude/skills/web-accessibility/SKILL.md +225 -0
- package/.agents/generated/gemini/skills/adapters/SKILL.md +135 -0
- package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +107 -0
- package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +151 -0
- package/.agents/generated/gemini/skills/context-manager/SKILL.md +156 -0
- package/.agents/generated/gemini/skills/context-os/SKILL.md +200 -0
- package/.agents/generated/gemini/skills/database/SKILL.md +200 -0
- package/.agents/generated/gemini/skills/ddd/SKILL.md +314 -0
- package/.agents/generated/gemini/skills/decisions/SKILL.md +143 -0
- package/.agents/generated/gemini/skills/docker/SKILL.md +144 -0
- package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +423 -0
- package/.agents/generated/gemini/skills/fastapi/SKILL.md +209 -0
- package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +167 -0
- package/.agents/generated/gemini/skills/generators/SKILL.md +142 -0
- package/.agents/generated/gemini/skills/graphify/SKILL.md +205 -0
- package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +193 -0
- package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +250 -0
- package/.agents/generated/gemini/skills/interview-me/SKILL.md +96 -0
- package/.agents/generated/gemini/skills/microservices/SKILL.md +227 -0
- package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +114 -0
- package/.agents/generated/gemini/skills/nestjs/SKILL.md +204 -0
- package/.agents/generated/gemini/skills/nextjs/SKILL.md +298 -0
- package/.agents/generated/gemini/skills/node/SKILL.md +323 -0
- package/.agents/generated/gemini/skills/performance/SKILL.md +185 -0
- package/.agents/generated/gemini/skills/ponytail-mindset/SKILL.md +261 -0
- package/.agents/generated/gemini/skills/react/SKILL.md +332 -0
- package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +152 -0
- package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +118 -0
- package/.agents/generated/gemini/skills/security/SKILL.md +355 -0
- package/.agents/generated/gemini/skills/soft-design/SKILL.md +109 -0
- package/.agents/generated/gemini/skills/state-management/SKILL.md +129 -0
- package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +99 -0
- package/.agents/generated/gemini/skills/system-design/SKILL.md +631 -0
- package/.agents/generated/gemini/skills/testing/SKILL.md +166 -0
- package/.agents/generated/gemini/skills/typescript/SKILL.md +275 -0
- package/.agents/generated/gemini/skills/ui-design/SKILL.md +170 -0
- package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +460 -0
- package/.agents/generated/gemini/skills/ux-design/SKILL.md +177 -0
- package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +82 -0
- package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +300 -0
- package/.agents/mcp/runtime.py +454 -0
- package/.agents/mcp/server.mjs +189373 -0
- package/.agents/plugins.js +574 -0
- package/.agents/profiles.js +267 -0
- package/.agents/resolver.js +336 -0
- package/.agents/skills-index.json +200 -0
- package/.agents/skills.json +6 -0
- package/.agents/validate.js +500 -0
- package/LICENSE +21 -0
- package/README.md +415 -0
- package/benchmarks/gemini-issues.js +533 -0
- package/bin/index.js +458 -0
- package/package.json +70 -0
- package/registry.json +53 -0
- package/registry.schema.json +32 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Web Performance & Core Web Vitals
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Enforces high-efficiency frontend and full-stack performance standards to achieve exceptional Core Web Vitals: Largest Contentful Paint (LCP < 2.5s), Interaction to Next Paint (INP < 200ms), and Cumulative Layout Shift (CLS < 0.1).
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
Activate whenever analyzing, profiling, writing, or optimizing page loading speeds, network waterfalls, script bundling, animation frame rates, or data caching.
|
|
10
|
+
|
|
11
|
+
## Negative Constraints (What NOT to Do)
|
|
12
|
+
|
|
13
|
+
1. **NEVER introduce async waterfalls**: Do not chain sequential `await` calls when requests can be executed concurrently via `Promise.all()`.
|
|
14
|
+
2. **NEVER import large full libraries when only a utility is needed**: Never `import _ from 'lodash'`; use `import debounce from 'lodash/debounce'` or native alternatives.
|
|
15
|
+
3. **NEVER render images or videos without explicit aspect ratios**: Always provide `width` and `height` or `aspect-ratio` to avoid Cumulative Layout Shift (CLS).
|
|
16
|
+
4. **NEVER trigger synchronous layout thrashing**: Do not alternate between reading layout properties (`offsetHeight`, `getBoundingClientRect`) and writing styles in loops.
|
|
17
|
+
5. **NEVER animate non-composited properties**: Animate only GPU-composited CSS properties (`transform`, `opacity`). Never animate `width`, `height`, `top`, `left`, or `margin`.
|
|
18
|
+
|
|
19
|
+
## Rules & Patterns
|
|
20
|
+
|
|
21
|
+
### 1. Vercel Optimization Hierarchy by Impact
|
|
22
|
+
|
|
23
|
+
| Priority | Category | Key Optimization Target | Expected Impact |
|
|
24
|
+
|:---|:---|:---|:---|
|
|
25
|
+
| **1. CRITICAL** | **Eliminating Waterfalls** | Parallel data fetching (`Promise.all`), Suspense streaming | **30–60% faster LCP** |
|
|
26
|
+
| **2. CRITICAL** | **Bundle Size Optimization** | Direct submodule imports, `next/dynamic`, deferring 3rd party scripts | **40–70% smaller initial JS** |
|
|
27
|
+
| **3. HIGH** | **Server-Side & RSC Caching** | `React.cache()` request deduplication, edge SSR caching | **Lower TTFB & DB load** |
|
|
28
|
+
| **4. MEDIUM-HIGH** | **Client Query Optimization** | SWR / TanStack Query stale-while-revalidate, deduplication | **Zero redundant network calls** |
|
|
29
|
+
| **5. MEDIUM** | **Render & DOM Optimization** | Virtualization for large lists, state colocation, `:focus-visible` | **Smooth 60 FPS / INP < 100ms** |
|
|
30
|
+
|
|
31
|
+
### 2. Eliminating Network Waterfalls
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// [GOOD] Parallel execution
|
|
35
|
+
const [user, notifications] = await Promise.all([
|
|
36
|
+
fetchUser(),
|
|
37
|
+
fetchNotifications(),
|
|
38
|
+
]);
|
|
39
|
+
const posts = await fetchPosts(user.id);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3. Layout Shift & Visual Stability (CLS < 0.1)
|
|
43
|
+
|
|
44
|
+
- **Images & Video**: Always supply `width`, `height`, and `sizes` or CSS `aspect-ratio: 16 / 9`.
|
|
45
|
+
- **Dynamic Content**: Reserve layout space for dynamically loaded widgets with min-height placeholders or skeletons.
|
|
46
|
+
- **Tabular Numbers**: Use `font-feature-settings: "tnum"` / `font-variant-numeric: tabular-nums` for counters, clocks, and tables to prevent number width jitter.
|
|
47
|
+
|
|
48
|
+
## Code Examples
|
|
49
|
+
|
|
50
|
+
See `EXAMPLES.md` for detailed performance patterns and benchmark snippets.
|
|
51
|
+
|
|
52
|
+
## Validation Checklist
|
|
53
|
+
|
|
54
|
+
- [ ] LCP target is < 2.5s with preloaded critical fonts and LCP image `priority`.
|
|
55
|
+
- [ ] No sequential `await` waterfalls in API routes or Server Components.
|
|
56
|
+
- [ ] All animated elements use only `transform` and `opacity`.
|
|
57
|
+
- [ ] `prefers-reduced-motion` media queries are respected.
|
|
58
|
+
- [ ] Large tables / lists (> 100 items) utilize virtualization.
|
|
59
|
+
|
|
60
|
+
## Common Mistakes
|
|
61
|
+
|
|
62
|
+
- Chaining independent async requests instead of using `Promise.all`.
|
|
63
|
+
- Animating layout-triggering properties (`height`, `width`, `top`) causing jank.
|
|
64
|
+
- Missing image dimensions causing layout shift when images finish loading.
|
|
65
|
+
|
|
66
|
+
## Integration Notes
|
|
67
|
+
|
|
68
|
+
- Pairs with `nextjs` and `react` for App Router caching and component lifecycle tuning.
|
|
69
|
+
- Pairs with `ui-ux-pro` for smooth animations and responsive design tokens.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# performance Examples — Anti-patterns vs ContextOS Standard
|
|
73
|
+
|
|
74
|
+
## Example 1: Dynamic Imports for Heavy Libraries
|
|
75
|
+
|
|
76
|
+
### Anti-pattern: Static Import of Heavy Visualizers in Initial Bundle
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// BAD: Adds 800KB (Monaco editor or Three.js) to the critical first-paint bundle!
|
|
80
|
+
import { CodeEditor } from '@/components/CodeEditor';
|
|
81
|
+
|
|
82
|
+
export default function Page() {
|
|
83
|
+
return <div><CodeEditor /></div>;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Best practice: ContextOS Standard (Lazy Load on Demand)
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// GOOD: Dynamic import splits chunk, only downloads when component renders
|
|
91
|
+
import dynamic from 'next/dynamic';
|
|
92
|
+
|
|
93
|
+
const CodeEditor = dynamic(
|
|
94
|
+
() => import('@/components/CodeEditor'),
|
|
95
|
+
{ loading: () => <EditorSkeleton />, ssr: false }
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
export default function Page() {
|
|
99
|
+
return <div><CodeEditor /></div>;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
# performance Troubleshooting & Common Mistakes
|
|
104
|
+
|
|
105
|
+
## 1. Cumulative Layout Shift (CLS) from Images & Fonts
|
|
106
|
+
|
|
107
|
+
- **Symptom**: Page content jumps around as images and custom fonts load.
|
|
108
|
+
- **Root Cause**: Missing width and height attributes on image tags and FOUT (Flash of Unstyled Text).
|
|
109
|
+
- **Fix**: Always specify aspect-ratio or width/height on images, and use next/font to preload web fonts with fallback sizing.
|
|
110
|
+
|
|
111
|
+
## 2. High Interaction to Next Paint (INP)
|
|
112
|
+
|
|
113
|
+
- **Symptom**: User clicks a button and the UI freezes for 200ms+ before responding.
|
|
114
|
+
- **Root Cause**: Long task blocking the main thread during event dispatch.
|
|
115
|
+
- **Fix**: Defer non-critical state updates using startTransition() or split heavy computation with Web Workers.
|
|
116
|
+
|
|
117
|
+
## 3. Unoptimized SVG / Icon Overload
|
|
118
|
+
|
|
119
|
+
- **Symptom**: Huge DOM node count and slow initial render times.
|
|
120
|
+
- **Root Cause**: Rendering 500 inline SVG icons with complex paths.
|
|
121
|
+
- **Fix**: Use SVG sprite sheets, dynamic icon loaders, or lightweight canvas rendering for dense data visualizations.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# ponytail-mindset
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Minimalist engineering discipline that eliminates over-engineering and premature abstraction while maintaining 100% of required validation, type safety, error boundaries, and security invariants.
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
Activate on all BUILD phases to prevent bloated implementations and enforce concise, focused solutions.
|
|
10
|
+
|
|
11
|
+
## Rules & Patterns
|
|
12
|
+
|
|
13
|
+
Based on [DietrichGebert/ponytail](https://github.com/DietrichGebert/ponytail).
|
|
14
|
+
|
|
15
|
+
> _He says nothing. He writes one line. It works._
|
|
16
|
+
|
|
17
|
+
**Core Impact**: Dramatically reduces code footprint by eliminating premature abstraction, YAGNI violations, and boilerplate, while keeping all safety invariants (validation, error handling, security) 100% intact.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### Core Principle
|
|
22
|
+
|
|
23
|
+
> **The best code is code you don't write.**
|
|
24
|
+
> Write only what the task strictly needs. Lazy about the solution, never about reading and understanding.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
### The 7-Rung Decision Ladder
|
|
29
|
+
|
|
30
|
+
**Before writing ANY code**, stop and check each rung in order. Stop at the first rung that holds:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
1. Does this need to exist?
|
|
34
|
+
→ No: YAGNI — skip it entirely. Don't build for "future use."
|
|
35
|
+
|
|
36
|
+
2. Already in this codebase or component library?
|
|
37
|
+
→ Yes: Reuse it. Don't rewrite. Call the existing function/component/module.
|
|
38
|
+
→ For UI: Check shadcn/ui FIRST. Before building a complex UI element from scratch, check if it exists in the component library. If yes, generate the install command: npx shadcn@latest add dialog — never manually rewrite what shadcn already provides.
|
|
39
|
+
|
|
40
|
+
3. Standard library does it?
|
|
41
|
+
→ Yes: Use it. Don't write formatDate() — use Intl.DateTimeFormat or dayjs.
|
|
42
|
+
|
|
43
|
+
4. Native platform feature?
|
|
44
|
+
→ Yes: Use it. Don't install flatpickr when <input type="date"> exists.
|
|
45
|
+
→ Exception for UI Components: If a native HTML element (like <input type="date"> or <select>) CANNOT be styled consistently across Chrome, Safari, and Firefox to match the premium design system — use the established component library (e.g., shadcn/ui <DatePicker>, <Select>) instead. Cross-browser inconsistency is a legitimate reason to NOT use native.
|
|
46
|
+
|
|
47
|
+
5. Already-installed dependency?
|
|
48
|
+
→ Yes: Use it. Don't install a new library to do what an existing one can.
|
|
49
|
+
|
|
50
|
+
6. Can it be done in one line?
|
|
51
|
+
→ Yes: One line. No abstraction layer needed.
|
|
52
|
+
|
|
53
|
+
7. Only then: write the MINIMUM that works.
|
|
54
|
+
→ No classes when a function works. No module when an inline does.
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### The Rule of Three (Do Not Abstract Early)
|
|
60
|
+
|
|
61
|
+
- **First occurrence**: Write it inline directly where it is needed.
|
|
62
|
+
- **Second occurrence**: Duplicate it cleanly. Duplication is cheaper than the wrong abstraction.
|
|
63
|
+
- **Third occurrence**: Only now extract a shared helper or utility.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### 10 Concrete Over-Engineering Red Flags
|
|
68
|
+
|
|
69
|
+
1. Creating a `GenericRepository<T>` when you only have 2 database tables.
|
|
70
|
+
2. Creating a custom state machine or complex reducer for 2 boolean flags.
|
|
71
|
+
3. Adding a configuration file or environment variables for values that never change.
|
|
72
|
+
4. Writing custom retry/circuit-breaker logic when native `fetch` or SDK already handles it.
|
|
73
|
+
5. Building a generic `BaseService` with 15 hook methods implemented by only one class.
|
|
74
|
+
6. Wrapping every standard library call in a custom helper class (`StringUtils`, `DateUtils`, `ObjectUtils`).
|
|
75
|
+
7. Creating a multi-level folder structure (`domains/auth/adapters/driving/rest/controllers/dto/`) for a 30-line microservice.
|
|
76
|
+
8. Writing custom mock frameworks when Vitest/Jest/Node test runner provide standard mocks.
|
|
77
|
+
9. Installing a 50KB npm package for a 3-line utility (e.g. `left-pad`, `is-number`, `deep-clone`).
|
|
78
|
+
10. Pre-optimizing caching and indexing for endpoints serving 10 requests a day.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### The Sacred Exceptions (NEVER Cut These)
|
|
83
|
+
|
|
84
|
+
The ladder applies to features and abstractions. These 4 areas are **non-negotiable** and **never simplified away**:
|
|
85
|
+
|
|
86
|
+
#### 1. Input Validation
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
// [GOOD] Always validate — even if "internal" API
|
|
90
|
+
function createUser(data) {
|
|
91
|
+
if (!data.email || !isValidEmail(data.email)) {
|
|
92
|
+
throw new ValidationError('Invalid email');
|
|
93
|
+
}
|
|
94
|
+
return db.insert('users', data);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// [BAD] Never skip validation for "speed"
|
|
98
|
+
function createUser(data) {
|
|
99
|
+
return db.insert('users', data); // NEVER
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### 2. Error Handling
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
// [GOOD] Always handle errors explicitly
|
|
107
|
+
async function fetchUser(id) {
|
|
108
|
+
try {
|
|
109
|
+
const user = await db.findById(id);
|
|
110
|
+
if (!user) throw new NotFoundError(`User ${id} not found`);
|
|
111
|
+
return user;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
logger.error('fetchUser failed', { id, err });
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### 3. Security Checks
|
|
120
|
+
|
|
121
|
+
- Authorization check BEFORE every query or mutation.
|
|
122
|
+
- Parameterized queries everywhere — zero string concatenation in SQL.
|
|
123
|
+
- Strict sanitization of all rendered HTML and markdown.
|
|
124
|
+
|
|
125
|
+
#### 4. Type Safety & Behavioral Tests
|
|
126
|
+
|
|
127
|
+
- Strict TypeScript types — no `any` evasion.
|
|
128
|
+
- Tests covering happy path, 4xx, and 5xx edge cases.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Code Examples
|
|
133
|
+
|
|
134
|
+
### Native Platform vs Over-Built Package
|
|
135
|
+
|
|
136
|
+
**Over-build**:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm install flatpickr
|
|
140
|
+
# Creates DatePickerWrapper.jsx (45 lines) + useDatePicker.js (30 lines) + styles (60 lines)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Ponytail approach (rung 4)**:
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<input type="date" name="date" aria-label="Appointment date" />
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Next.js App Router Server Action vs REST Endpoint
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Instead of /api/users/[id]/route.ts + custom fetch wrapper:
|
|
153
|
+
"use server";
|
|
154
|
+
|
|
155
|
+
export async function updateUser(id: string, data: UpdateUserInput) {
|
|
156
|
+
const session = await getSession(); // auth check — never skip
|
|
157
|
+
if (session?.userId !== id) throw new Error("Forbidden");
|
|
158
|
+
return db.users.update(id, data);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Validation Checklist
|
|
165
|
+
|
|
166
|
+
- [ ] Every new dependency has been verified: cannot be solved with native platform or existing dependencies.
|
|
167
|
+
- [ ] No single-use abstractions, wrappers, or interfaces created.
|
|
168
|
+
- [ ] Sacred exceptions preserved: 100% input validation, explicit error handling, security checks intact.
|
|
169
|
+
- [ ] All code written passes all existing unit and integration tests.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Common Mistakes
|
|
174
|
+
|
|
175
|
+
- **Cutting validation to write less code**: The goal is less architecture/boilerplate, never less safety.
|
|
176
|
+
- **Creating utilities "for future use"**: Only write utilities when used 3+ times.
|
|
177
|
+
- **Rewriting component libraries**: Building custom modals, tabs, or tooltips from scratch when shadcn/ui or Radix is already in the project.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Integration Notes
|
|
182
|
+
|
|
183
|
+
- Runs at the start of every `[PHASE: Build]` and `[PHASE: Review]`.
|
|
184
|
+
- Enforces minimalism alongside `system-design` (think at scale, implement minimally).
|
|
185
|
+
- Pairs with `impeccable-design` for UI tasks.
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ponytail-mindset Examples — Anti-patterns vs ContextOS Standard
|
|
189
|
+
|
|
190
|
+
## Example 1: Data Formatting and Manipulation
|
|
191
|
+
|
|
192
|
+
### Anti-pattern: Over-engineered Custom Utility Class
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// BAD: 40 lines of boilerplate for relative date formatting
|
|
196
|
+
export class DateFormatterService {
|
|
197
|
+
private static instance: DateFormatterService;
|
|
198
|
+
public static getInstance() { /* singleton boilerplate */ }
|
|
199
|
+
public formatRelative(date: Date): string {
|
|
200
|
+
const diff = Date.now() - date.getTime();
|
|
201
|
+
// 30 lines of manual math, plurals, and string building
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Best practice: ContextOS Standard (Standard Library Native API)
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// GOOD: Native Intl API, zero bundle cost, handles all locales
|
|
210
|
+
export const formatRelativeTime = (date: Date, locale = 'en'): string => {
|
|
211
|
+
const diffDays = Math.round((date.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
|
|
212
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(diffDays, 'day');
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Example 2: Component Library Reuse
|
|
219
|
+
|
|
220
|
+
### Anti-pattern: Hand-rolled Modal from Scratch
|
|
221
|
+
|
|
222
|
+
```text
|
|
223
|
+
BAD: Writing custom overlay DOM, manual scroll locking, manual focus trapping,
|
|
224
|
+
and custom keydown listeners. Burns 300+ lines of fragile code.
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Best practice: ContextOS Standard (Leverage Established Primitives)
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# GOOD: Install battle-tested primitive that handles ARIA, portals, and keyboard navigation
|
|
231
|
+
npx shadcn@latest add dialog
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
# ponytail-mindset Troubleshooting & Common Mistakes
|
|
235
|
+
|
|
236
|
+
## 1. Conflating Minimalism with Cutting Safety Guards
|
|
237
|
+
|
|
238
|
+
- **Symptom**: Agent removes input validation, error handling, or security checks in the name of "less code".
|
|
239
|
+
- **Root Cause**: Misunderstanding the Ponytail principle. Ponytail cuts unnecessary abstractions, never safety invariants.
|
|
240
|
+
- **Fix**: Invariant: Always retain 100% of input sanitization, error boundaries, and type safety checks.
|
|
241
|
+
|
|
242
|
+
## 2. "Just In Case" Speculative Coding (YAGNI Violation)
|
|
243
|
+
|
|
244
|
+
- **Symptom**: Adding config options, generics, and plugin interfaces for features not requested.
|
|
245
|
+
- **Root Cause**: Premature future-proofing.
|
|
246
|
+
- **Fix**: Apply Rung 1 of the ladder: If it doesn't solve the immediate requirement, do not write it.
|
|
247
|
+
|
|
248
|
+
## 3. Reinventing Installed Dependencies
|
|
249
|
+
|
|
250
|
+
- **Symptom**: Writing a deep-clone helper when Lodash or native structuredClone is available.
|
|
251
|
+
- **Root Cause**: Skipping inspection of package.json and runtime environment.
|
|
252
|
+
- **Fix**: Inspect installed dependencies before writing utility functions.
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# React Engineering & Performance Best Practices
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Enforces declarative, component-driven UI architecture with optimal re-render cycles, state colocation, responsive optimistic updates, and robust accessibility standards.
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
Activate whenever creating, refactoring, or optimizing React functional components, custom hooks, context providers, or UI interaction states.
|
|
10
|
+
|
|
11
|
+
## Negative Constraints (What NOT to Do)
|
|
12
|
+
|
|
13
|
+
1. **NEVER use `useEffect` to synchronize or compute derived state**: Calculate derived state inline during render. Use `useMemo` only for computationally intensive derivations.
|
|
14
|
+
2. **NEVER use array indices as `key` props on dynamic or reorderable lists**: Always use stable, unique entity identifiers (`item.id`).
|
|
15
|
+
3. **NEVER mutate React state directly**: Always return new immutable references (`[...prev, newItem]` or `{ ...prev, key: value }`).
|
|
16
|
+
4. **NEVER declare subcomponents inside the render body of parent components**: Declare components at module scope or in dedicated files to prevent DOM node remounting and lost focus state.
|
|
17
|
+
5. **NEVER create memory leaks in `useEffect`**: Always provide clean-up functions for event listeners, `AbortController`, timers, and websocket subscriptions.
|
|
18
|
+
6. **NEVER lift state higher than necessary**: Colocate state to the nearest common ancestor or leaf component to prevent wasteful re-renders of unrelated subtrees.
|
|
19
|
+
|
|
20
|
+
## Rules & Patterns
|
|
21
|
+
|
|
22
|
+
### 1. State Colocation & Re-render Optimization
|
|
23
|
+
|
|
24
|
+
- **State Colocation**: Keep state as close as possible to the components that consume it.
|
|
25
|
+
- **Composition to Prevent Re-renders**: Pass expensive static subtrees as `children` to wrapper components holding state so the children do not re-render when the wrapper updates.
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
export function ExpandableCard({ title, children }: { title: string; children: React.ReactNode }) {
|
|
29
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="rounded-xl border p-4">
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
onClick={() => setIsOpen(v => !v)}
|
|
36
|
+
className="flex w-full justify-between font-semibold"
|
|
37
|
+
aria-expanded={isOpen}
|
|
38
|
+
>
|
|
39
|
+
<span>{title}</span>
|
|
40
|
+
<span>{isOpen ? '−' : '+'}</span>
|
|
41
|
+
</button>
|
|
42
|
+
{isOpen && <div className="mt-3 pt-3 border-t">{children}</div>}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Optimistic UI Updates & Concurrent Actions (`useOptimistic`, `useTransition`)
|
|
49
|
+
|
|
50
|
+
- Provide instantaneous visual feedback for user actions without waiting for server network roundtrips.
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { useOptimistic, useTransition } from 'react';
|
|
54
|
+
|
|
55
|
+
export function TodoList({ todos, onAdd }: { todos: Todo[]; onAdd: (text: string) => Promise<void> }) {
|
|
56
|
+
const [isPending, startTransition] = useTransition();
|
|
57
|
+
const [optimisticTodos, addOptimisticTodo] = useOptimistic(
|
|
58
|
+
todos,
|
|
59
|
+
(state, newText: string) => [...state, { id: 'temp-' + Date.now(), text: newText, isPending: true }]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const handleAction = async (formData: FormData) => {
|
|
63
|
+
const text = formData.get('todo') as string;
|
|
64
|
+
if (!text?.trim()) return;
|
|
65
|
+
|
|
66
|
+
startTransition(async () => {
|
|
67
|
+
addOptimisticTodo(text);
|
|
68
|
+
await onAdd(text);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<form action={handleAction} className="space-y-4">
|
|
74
|
+
<input name="todo" placeholder="Add a new task..." className="border p-2 rounded" />
|
|
75
|
+
<button type="submit" disabled={isPending} className="bg-primary text-white px-4 py-2 rounded">
|
|
76
|
+
{isPending ? 'Saving...' : 'Add'}
|
|
77
|
+
</button>
|
|
78
|
+
<ul className="divide-y">
|
|
79
|
+
{optimisticTodos.map(todo => (
|
|
80
|
+
<li key={todo.id} className={todo.isPending ? 'opacity-50 italic' : ''}>
|
|
81
|
+
{todo.text}
|
|
82
|
+
</li>
|
|
83
|
+
))}
|
|
84
|
+
</ul>
|
|
85
|
+
</form>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 3. Derived State vs. Effects Anti-Pattern
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
// [GOOD] Computed directly during render (or memoized if expensive)
|
|
94
|
+
function SearchResults({ query, items }: { query: string; items: Item[] }) {
|
|
95
|
+
const filtered = useMemo(() => {
|
|
96
|
+
const q = query.trim().toLowerCase();
|
|
97
|
+
if (!q) return items;
|
|
98
|
+
return items.filter(i => i.title.toLowerCase().includes(q));
|
|
99
|
+
}, [query, items]);
|
|
100
|
+
|
|
101
|
+
return <List items={filtered} />;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Code Examples
|
|
106
|
+
|
|
107
|
+
See `EXAMPLES.md` for detailed code examples and hook implementations.
|
|
108
|
+
|
|
109
|
+
## Validation Checklist
|
|
110
|
+
|
|
111
|
+
- [ ] Zero `useEffect` hooks used for derived calculations.
|
|
112
|
+
- [ ] Every list mapping has a unique, non-index entity ID key.
|
|
113
|
+
- [ ] Subcomponents declared in parent render functions are extracted to top-level scope.
|
|
114
|
+
- [ ] Effects with event listeners, timers, or abortable requests include clean-up returns.
|
|
115
|
+
- [ ] Reusable components are composed cleanly via `children` or render props.
|
|
116
|
+
|
|
117
|
+
## Common Mistakes
|
|
118
|
+
|
|
119
|
+
- Setting state inside `useEffect` based on prop changes rather than deriving values inline.
|
|
120
|
+
- Declaring nested components within component bodies.
|
|
121
|
+
- Using index keys causing input focus loss or animations breaking on list mutations.
|
|
122
|
+
|
|
123
|
+
## Integration Notes
|
|
124
|
+
|
|
125
|
+
- Pairs with `typescript` for type safety on props, generics, and ref forwarding.
|
|
126
|
+
- Pairs with `ui-ux-pro` and `web-accessibility` for UI tokens and ARIA standards.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# React Examples — Anti-patterns vs ContextOS Standard
|
|
130
|
+
|
|
131
|
+
## Example 1: Derived State vs. useEffect
|
|
132
|
+
|
|
133
|
+
### Anti-pattern: Anti-pattern (Redundant state + extra render with useEffect)
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
// BAD: causes an unnecessary extra render cycle and potential state desync
|
|
137
|
+
function OrderSummary({ items }: { items: CartItem[] }) {
|
|
138
|
+
const [total, setTotal] = useState(0);
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const calculated = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
|
|
142
|
+
setTotal(calculated);
|
|
143
|
+
}, [items]);
|
|
144
|
+
|
|
145
|
+
return <div>Total: ${total}</div>;
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Best practice: ContextOS Standard (Inline derived calculation / useMemo)
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
// GOOD: calculated instantly during render with zero extra render pass
|
|
153
|
+
function OrderSummary({ items }: { items: CartItem[] }) {
|
|
154
|
+
const total = useMemo(
|
|
155
|
+
() => items.reduce((sum, item) => sum + item.price * item.quantity, 0),
|
|
156
|
+
[items]
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return <div>Total: ${total.toFixed(2)}</div>;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Example 2: Custom Hook Encapsulation
|
|
166
|
+
|
|
167
|
+
### Anti-pattern: Anti-pattern (Scattered listener logic inside component)
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
// BAD: window listener logic cluttering UI component
|
|
171
|
+
function NavHeader() {
|
|
172
|
+
const [isScrolled, setIsScrolled] = useState(false);
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
const handleScroll = () => setIsScrolled(window.scrollY > 50);
|
|
175
|
+
window.addEventListener('scroll', handleScroll);
|
|
176
|
+
return () => window.removeEventListener('scroll', handleScroll);
|
|
177
|
+
}, []);
|
|
178
|
+
return <header className={isScrolled ? 'scrolled' : ''}>Header</header>;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Best practice: ContextOS Standard (Reusable Custom Hook)
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
// GOOD: extracted into a reusable, testable custom hook
|
|
186
|
+
export function useScrollThreshold(threshold = 50): boolean {
|
|
187
|
+
const [isPassed, setIsPassed] = useState(() => typeof window !== 'undefined' && window.scrollY > threshold);
|
|
188
|
+
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
let ticking = false;
|
|
191
|
+
const handleScroll = () => {
|
|
192
|
+
if (!ticking) {
|
|
193
|
+
window.requestAnimationFrame(() => {
|
|
194
|
+
setIsPassed(window.scrollY > threshold);
|
|
195
|
+
ticking = false;
|
|
196
|
+
});
|
|
197
|
+
ticking = true;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
202
|
+
return () => window.removeEventListener('scroll', handleScroll);
|
|
203
|
+
}, [threshold]);
|
|
204
|
+
|
|
205
|
+
return isPassed;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
# react Troubleshooting & Common Mistakes
|
|
210
|
+
|
|
211
|
+
## 1. Infinite Render Loops in useEffect
|
|
212
|
+
|
|
213
|
+
- **Symptom**: Browser freezes, "Maximum update depth exceeded" error.
|
|
214
|
+
- **Root Cause**: Creating new object or array literals inside component body and passing them to useEffect dependency array.
|
|
215
|
+
- **Fix**: Colocate state, compute derived state during render without useEffect, or use primitive dependency values.
|
|
216
|
+
|
|
217
|
+
## 2. Stale Closures in Callbacks
|
|
218
|
+
|
|
219
|
+
- **Symptom**: Event handler or setTimeout accesses outdated state values.
|
|
220
|
+
- **Root Cause**: Callback closing over initial state without updated dependency.
|
|
221
|
+
- **Fix**: Use functional state updates (`setCount(c => c + 1)`) or `useRef` for mutable references.
|
|
222
|
+
|
|
223
|
+
## 3. Prop Drilling vs Context Performance
|
|
224
|
+
|
|
225
|
+
- **Symptom**: Changing a small state variable causes the entire component tree to re-render.
|
|
226
|
+
- **Root Cause**: Storing rapidly changing state in a single monolithic React Context.
|
|
227
|
+
- **Fix**: Split contexts by domain or migrate client UI state to Zustand with granular selectors.
|