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,332 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: React
|
|
3
|
+
description: >
|
|
4
|
+
ContextOS skill for React
|
|
5
|
+
---
|
|
6
|
+
# React Engineering & Performance Best Practices
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Enforces declarative, component-driven UI architecture with optimal re-render cycles, state colocation, responsive optimistic updates, and robust accessibility standards.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
Activate whenever creating, refactoring, or optimizing React functional components, custom hooks, context providers, or UI interaction states.
|
|
15
|
+
|
|
16
|
+
## Negative Constraints (What NOT to Do)
|
|
17
|
+
|
|
18
|
+
1. **NEVER use `useEffect` to synchronize or compute derived state**: Calculate derived state inline during render. Use `useMemo` only for computationally intensive derivations.
|
|
19
|
+
2. **NEVER use array indices as `key` props on dynamic or reorderable lists**: Always use stable, unique entity identifiers (`item.id`).
|
|
20
|
+
3. **NEVER mutate React state directly**: Always return new immutable references (`[...prev, newItem]` or `{ ...prev, key: value }`).
|
|
21
|
+
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.
|
|
22
|
+
5. **NEVER create memory leaks in `useEffect`**: Always provide clean-up functions for event listeners, `AbortController`, timers, and websocket subscriptions.
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
## Rules & Patterns
|
|
26
|
+
|
|
27
|
+
### 1. State Colocation & Re-render Optimization
|
|
28
|
+
|
|
29
|
+
- **State Colocation**: Keep state as close as possible to the components that consume it.
|
|
30
|
+
- **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.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
export function ExpandableCard({ title, children }: { title: string; children: React.ReactNode }) {
|
|
34
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="rounded-xl border p-4">
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
onClick={() => setIsOpen(v => !v)}
|
|
41
|
+
className="flex w-full justify-between font-semibold"
|
|
42
|
+
aria-expanded={isOpen}
|
|
43
|
+
>
|
|
44
|
+
<span>{title}</span>
|
|
45
|
+
<span>{isOpen ? '−' : '+'}</span>
|
|
46
|
+
</button>
|
|
47
|
+
{isOpen && <div className="mt-3 pt-3 border-t">{children}</div>}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Optimistic UI Updates & Concurrent Actions (`useOptimistic`, `useTransition`)
|
|
54
|
+
|
|
55
|
+
- Provide instantaneous visual feedback for user actions without waiting for server network roundtrips.
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { useOptimistic, useTransition } from 'react';
|
|
59
|
+
|
|
60
|
+
export function TodoList({ todos, onAdd }: { todos: Todo[]; onAdd: (text: string) => Promise<void> }) {
|
|
61
|
+
const [isPending, startTransition] = useTransition();
|
|
62
|
+
const [optimisticTodos, addOptimisticTodo] = useOptimistic(
|
|
63
|
+
todos,
|
|
64
|
+
(state, newText: string) => [...state, { id: 'temp-' + Date.now(), text: newText, isPending: true }]
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const handleAction = async (formData: FormData) => {
|
|
68
|
+
const text = formData.get('todo') as string;
|
|
69
|
+
if (!text?.trim()) return;
|
|
70
|
+
|
|
71
|
+
startTransition(async () => {
|
|
72
|
+
addOptimisticTodo(text);
|
|
73
|
+
await onAdd(text);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<form action={handleAction} className="space-y-4">
|
|
79
|
+
<input name="todo" placeholder="Add a new task..." className="border p-2 rounded" />
|
|
80
|
+
<button type="submit" disabled={isPending} className="bg-primary text-white px-4 py-2 rounded">
|
|
81
|
+
{isPending ? 'Saving...' : 'Add'}
|
|
82
|
+
</button>
|
|
83
|
+
<ul className="divide-y">
|
|
84
|
+
{optimisticTodos.map(todo => (
|
|
85
|
+
<li key={todo.id} className={todo.isPending ? 'opacity-50 italic' : ''}>
|
|
86
|
+
{todo.text}
|
|
87
|
+
</li>
|
|
88
|
+
))}
|
|
89
|
+
</ul>
|
|
90
|
+
</form>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Derived State vs. Effects Anti-Pattern
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
// [GOOD] Computed directly during render (or memoized if expensive)
|
|
99
|
+
function SearchResults({ query, items }: { query: string; items: Item[] }) {
|
|
100
|
+
const filtered = useMemo(() => {
|
|
101
|
+
const q = query.trim().toLowerCase();
|
|
102
|
+
if (!q) return items;
|
|
103
|
+
return items.filter(i => i.title.toLowerCase().includes(q));
|
|
104
|
+
}, [query, items]);
|
|
105
|
+
|
|
106
|
+
return <List items={filtered} />;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Code Examples
|
|
111
|
+
|
|
112
|
+
See `EXAMPLES.md` for detailed code examples and hook implementations.
|
|
113
|
+
|
|
114
|
+
## Validation Checklist
|
|
115
|
+
|
|
116
|
+
- [ ] Zero `useEffect` hooks used for derived calculations.
|
|
117
|
+
- [ ] Every list mapping has a unique, non-index entity ID key.
|
|
118
|
+
- [ ] Subcomponents declared in parent render functions are extracted to top-level scope.
|
|
119
|
+
- [ ] Effects with event listeners, timers, or abortable requests include clean-up returns.
|
|
120
|
+
- [ ] Reusable components are composed cleanly via `children` or render props.
|
|
121
|
+
|
|
122
|
+
## Common Mistakes
|
|
123
|
+
|
|
124
|
+
- Setting state inside `useEffect` based on prop changes rather than deriving values inline.
|
|
125
|
+
- Declaring nested components within component bodies.
|
|
126
|
+
- Using index keys causing input focus loss or animations breaking on list mutations.
|
|
127
|
+
|
|
128
|
+
## Integration Notes
|
|
129
|
+
|
|
130
|
+
- Pairs with `typescript` for type safety on props, generics, and ref forwarding.
|
|
131
|
+
- Pairs with `ui-ux-pro` and `web-accessibility` for UI tokens and ARIA standards.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
<!-- Source: react.md -->
|
|
135
|
+
|
|
136
|
+
# React — Best Practices
|
|
137
|
+
|
|
138
|
+
## Component Architecture
|
|
139
|
+
|
|
140
|
+
- **Prefer function components** with hooks over class components
|
|
141
|
+
- **One component per file** — name file same as component
|
|
142
|
+
- **Composition over inheritance** — use children and render props
|
|
143
|
+
- **Keep components small** — if > 150 lines, split it
|
|
144
|
+
|
|
145
|
+
## Hooks
|
|
146
|
+
|
|
147
|
+
- **useState** for local state, **useReducer** for complex state
|
|
148
|
+
- **useEffect** — always specify dependencies, clean up subscriptions
|
|
149
|
+
- **Custom hooks** — extract reusable logic into `use*` functions
|
|
150
|
+
- **useMemo/useCallback** — only when you have measured a performance problem
|
|
151
|
+
|
|
152
|
+
## State Management
|
|
153
|
+
|
|
154
|
+
- **Local state first** — don't reach for global state until you need it
|
|
155
|
+
- **Lift state up** — find the closest common ancestor
|
|
156
|
+
- **Context** — for cross-cutting concerns (theme, auth, locale)
|
|
157
|
+
- **External store** (Zustand, Jotai) — for truly global, frequently updated state
|
|
158
|
+
|
|
159
|
+
## Patterns
|
|
160
|
+
|
|
161
|
+
### Container/Presenter
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
// Container — handles logic
|
|
165
|
+
function UserListContainer() {
|
|
166
|
+
const users = useUsers();
|
|
167
|
+
return <UserList users={users} />;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Presenter — handles display
|
|
171
|
+
function UserList({ users }: { users: User[] }) {
|
|
172
|
+
return <ul>{users.map(u => <UserItem key={u.id} user={u} />)}</ul>;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Error Boundaries
|
|
177
|
+
|
|
178
|
+
- Wrap major sections in Error Boundaries
|
|
179
|
+
- Provide meaningful fallback UI
|
|
180
|
+
- Log errors to monitoring service
|
|
181
|
+
|
|
182
|
+
### Loading States
|
|
183
|
+
|
|
184
|
+
- Always handle: `loading`, `error`, `empty`, `data` states
|
|
185
|
+
- Use Suspense where supported
|
|
186
|
+
- Show skeleton screens, not spinners
|
|
187
|
+
|
|
188
|
+
## Performance
|
|
189
|
+
|
|
190
|
+
- **React.memo** — only for expensive renders with stable props
|
|
191
|
+
- **Code splitting** — lazy load routes and heavy components
|
|
192
|
+
- **Virtualization** — for lists > 100 items
|
|
193
|
+
- **Image optimization** — use next/image or lazy loading
|
|
194
|
+
- **Avoid** — inline object/array creation in JSX props
|
|
195
|
+
|
|
196
|
+
## Anti-Patterns (Avoid)
|
|
197
|
+
|
|
198
|
+
- [FAIL] Props drilling more than 2 levels — use Context or state management
|
|
199
|
+
- [FAIL] useEffect for derived state — use useMemo instead
|
|
200
|
+
- [FAIL] Index as key — use stable unique IDs
|
|
201
|
+
- [FAIL] Mutating state directly — always create new references
|
|
202
|
+
- [FAIL] God components — split into smaller, focused components
|
|
203
|
+
- [FAIL] Business logic in components — extract to hooks or services
|
|
204
|
+
|
|
205
|
+
## Testing
|
|
206
|
+
|
|
207
|
+
- **React Testing Library** — test behavior, not implementation
|
|
208
|
+
- Test user interactions, not component internals
|
|
209
|
+
- Mock API calls, not React hooks
|
|
210
|
+
- Use `screen.getByRole` over `getByTestId`
|
|
211
|
+
|
|
212
|
+
## File Structure
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
components/
|
|
216
|
+
Button/
|
|
217
|
+
Button.tsx
|
|
218
|
+
Button.test.tsx
|
|
219
|
+
Button.module.css
|
|
220
|
+
index.ts
|
|
221
|
+
hooks/
|
|
222
|
+
useAuth.ts
|
|
223
|
+
useDebounce.ts
|
|
224
|
+
services/
|
|
225
|
+
api.ts
|
|
226
|
+
types/
|
|
227
|
+
user.ts
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
<!-- Source: EXAMPLES.md -->
|
|
231
|
+
|
|
232
|
+
# React Examples — Anti-patterns vs ContextOS Standard
|
|
233
|
+
|
|
234
|
+
## Example 1: Derived State vs. useEffect
|
|
235
|
+
|
|
236
|
+
### Anti-pattern: Anti-pattern (Redundant state + extra render with useEffect)
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
// BAD: causes an unnecessary extra render cycle and potential state desync
|
|
240
|
+
function OrderSummary({ items }: { items: CartItem[] }) {
|
|
241
|
+
const [total, setTotal] = useState(0);
|
|
242
|
+
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
const calculated = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
|
|
245
|
+
setTotal(calculated);
|
|
246
|
+
}, [items]);
|
|
247
|
+
|
|
248
|
+
return <div>Total: ${total}</div>;
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Best practice: ContextOS Standard (Inline derived calculation / useMemo)
|
|
253
|
+
|
|
254
|
+
```tsx
|
|
255
|
+
// GOOD: calculated instantly during render with zero extra render pass
|
|
256
|
+
function OrderSummary({ items }: { items: CartItem[] }) {
|
|
257
|
+
const total = useMemo(
|
|
258
|
+
() => items.reduce((sum, item) => sum + item.price * item.quantity, 0),
|
|
259
|
+
[items]
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
return <div>Total: ${total.toFixed(2)}</div>;
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Example 2: Custom Hook Encapsulation
|
|
269
|
+
|
|
270
|
+
### Anti-pattern: Anti-pattern (Scattered listener logic inside component)
|
|
271
|
+
|
|
272
|
+
```tsx
|
|
273
|
+
// BAD: window listener logic cluttering UI component
|
|
274
|
+
function NavHeader() {
|
|
275
|
+
const [isScrolled, setIsScrolled] = useState(false);
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
const handleScroll = () => setIsScrolled(window.scrollY > 50);
|
|
278
|
+
window.addEventListener('scroll', handleScroll);
|
|
279
|
+
return () => window.removeEventListener('scroll', handleScroll);
|
|
280
|
+
}, []);
|
|
281
|
+
return <header className={isScrolled ? 'scrolled' : ''}>Header</header>;
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Best practice: ContextOS Standard (Reusable Custom Hook)
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
// GOOD: extracted into a reusable, testable custom hook
|
|
289
|
+
export function useScrollThreshold(threshold = 50): boolean {
|
|
290
|
+
const [isPassed, setIsPassed] = useState(() => typeof window !== 'undefined' && window.scrollY > threshold);
|
|
291
|
+
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
let ticking = false;
|
|
294
|
+
const handleScroll = () => {
|
|
295
|
+
if (!ticking) {
|
|
296
|
+
window.requestAnimationFrame(() => {
|
|
297
|
+
setIsPassed(window.scrollY > threshold);
|
|
298
|
+
ticking = false;
|
|
299
|
+
});
|
|
300
|
+
ticking = true;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
305
|
+
return () => window.removeEventListener('scroll', handleScroll);
|
|
306
|
+
}, [threshold]);
|
|
307
|
+
|
|
308
|
+
return isPassed;
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
<!-- Source: TROUBLESHOOTING.md -->
|
|
313
|
+
|
|
314
|
+
# react Troubleshooting & Common Mistakes
|
|
315
|
+
|
|
316
|
+
## 1. Infinite Render Loops in useEffect
|
|
317
|
+
|
|
318
|
+
- **Symptom**: Browser freezes, "Maximum update depth exceeded" error.
|
|
319
|
+
- **Root Cause**: Creating new object or array literals inside component body and passing them to useEffect dependency array.
|
|
320
|
+
- **Fix**: Colocate state, compute derived state during render without useEffect, or use primitive dependency values.
|
|
321
|
+
|
|
322
|
+
## 2. Stale Closures in Callbacks
|
|
323
|
+
|
|
324
|
+
- **Symptom**: Event handler or setTimeout accesses outdated state values.
|
|
325
|
+
- **Root Cause**: Callback closing over initial state without updated dependency.
|
|
326
|
+
- **Fix**: Use functional state updates (`setCount(c => c + 1)`) or `useRef` for mutable references.
|
|
327
|
+
|
|
328
|
+
## 3. Prop Drilling vs Context Performance
|
|
329
|
+
|
|
330
|
+
- **Symptom**: Changing a small state variable causes the entire component tree to re-render.
|
|
331
|
+
- **Root Cause**: Storing rapidly changing state in a single monolithic React Context.
|
|
332
|
+
- **Fix**: Split contexts by domain or migrate client UI state to Zustand with granular selectors.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-best-practices
|
|
3
|
+
description: >
|
|
4
|
+
React and Next.js performance optimization guidelines from Vercel Engineering.
|
|
5
|
+
---
|
|
6
|
+
# Vercel React Best Practices
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 70 rules across 8 categories, prioritized by impact to guide automated refactoring, code generation, and production review.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- When authoring new React functional components or Next.js App Router pages.
|
|
15
|
+
- When implementing data fetching (client or server-side Server Actions, RSC).
|
|
16
|
+
- When reviewing pull requests for rendering bottlenecks or memory leaks.
|
|
17
|
+
- When optimizing bundle size, eliminating network waterfalls, or improving Core Web Vitals (LCP, INP, CLS).
|
|
18
|
+
|
|
19
|
+
## Rules & Patterns
|
|
20
|
+
|
|
21
|
+
### Rule Categories by Priority
|
|
22
|
+
|
|
23
|
+
| Priority | Category | Impact | Prefix |
|
|
24
|
+
|----------|----------|--------|--------|
|
|
25
|
+
| 1 | Eliminating Waterfalls | CRITICAL | `async-` |
|
|
26
|
+
| 2 | Bundle Size Optimization | CRITICAL | `bundle-` |
|
|
27
|
+
| 3 | Server-Side Performance | HIGH | `server-` |
|
|
28
|
+
| 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |
|
|
29
|
+
| 5 | Re-render Optimization | MEDIUM | `rerender-` |
|
|
30
|
+
| 6 | Rendering Performance | MEDIUM | `rendering-` |
|
|
31
|
+
| 7 | JavaScript Performance | LOW-MEDIUM | `js-` |
|
|
32
|
+
| 8 | Advanced Patterns | LOW | `advanced-` |
|
|
33
|
+
|
|
34
|
+
### 1. Eliminating Waterfalls (CRITICAL)
|
|
35
|
+
|
|
36
|
+
- `async-cheap-condition-before-await` - Check cheap sync conditions before awaiting flags or remote values.
|
|
37
|
+
- `async-defer-await` - Move await into branches where actually used.
|
|
38
|
+
- `async-parallel` - Use `Promise.all()` for independent asynchronous operations.
|
|
39
|
+
- `async-dependencies` - Use better-all for partial dependencies.
|
|
40
|
+
- `async-api-routes` - Start promises early, await late in API routes.
|
|
41
|
+
- `async-suspense-boundaries` - Use Suspense to stream content progressively.
|
|
42
|
+
|
|
43
|
+
### 2. Bundle Size Optimization (CRITICAL)
|
|
44
|
+
|
|
45
|
+
- `bundle-barrel-imports` - Import directly from specific modules, avoid broad barrel files (`index.ts`).
|
|
46
|
+
- `bundle-analyzable-paths` - Prefer statically analyzable import paths to avoid bloated traces.
|
|
47
|
+
- `bundle-dynamic-imports` - Use `next/dynamic` or `React.lazy()` for heavy interactive components.
|
|
48
|
+
- `bundle-defer-third-party` - Load analytics and logging scripts after hydration.
|
|
49
|
+
- `bundle-conditional` - Load modules only when feature flags or user actions require them.
|
|
50
|
+
- `bundle-preload` - Preload assets on hover or focus for perceived instant navigation.
|
|
51
|
+
|
|
52
|
+
### 3. Server-Side Performance (HIGH)
|
|
53
|
+
|
|
54
|
+
- `server-auth-actions` - Always authenticate server actions like API routes.
|
|
55
|
+
- `server-cache-react` - Use `React.cache()` for per-request deduplication.
|
|
56
|
+
- `server-cache-lru` - Use LRU cache for cross-request caching.
|
|
57
|
+
- `server-dedup-props` - Avoid duplicate serialization in RSC props.
|
|
58
|
+
- `server-hoist-static-io` - Hoist static I/O to module level.
|
|
59
|
+
- `server-no-shared-module-state` - Avoid module-level mutable request state in RSC/SSR.
|
|
60
|
+
- `server-serialization` - Minimize data passed across the server-client boundary.
|
|
61
|
+
- `server-parallel-fetching` - Restructure components to parallelize fetches.
|
|
62
|
+
- `server-after-nonblocking` - Use `after()` for non-blocking operations like analytics logging.
|
|
63
|
+
|
|
64
|
+
### 4. Client-Side Data Fetching (MEDIUM-HIGH)
|
|
65
|
+
|
|
66
|
+
- `client-swr-dedup` - Use SWR or TanStack Query for automatic request deduplication.
|
|
67
|
+
- `client-event-listeners` - Deduplicate global event listeners.
|
|
68
|
+
- `client-passive-event-listeners` - Use passive listeners for scroll and touch.
|
|
69
|
+
- `client-localstorage-schema` - Version and minimize data stored in localStorage.
|
|
70
|
+
|
|
71
|
+
### 5. Re-render Optimization (MEDIUM)
|
|
72
|
+
|
|
73
|
+
- `rerender-defer-reads` - Don't subscribe to state only used in callbacks.
|
|
74
|
+
- `rerender-memo` - Extract expensive work into memoized components.
|
|
75
|
+
- `rerender-memo-with-default-value` - Hoist default non-primitive props.
|
|
76
|
+
- `rerender-dependencies` - Use primitive dependencies in effects and callbacks.
|
|
77
|
+
- `rerender-derived-state` - Subscribe to derived booleans, not raw high-frequency values.
|
|
78
|
+
- `rerender-derived-state-no-effect` - Derive state during render, never in `useEffect`.
|
|
79
|
+
- `rerender-functional-setstate` - Use functional `setState` for stable callback references.
|
|
80
|
+
- `rerender-lazy-state-init` - Pass initializer functions to `useState` for expensive computations.
|
|
81
|
+
- `rerender-transitions` - Use `startTransition` for non-urgent state updates.
|
|
82
|
+
- `rerender-use-deferred-value` - Defer expensive renders to keep input responsive.
|
|
83
|
+
- `rerender-no-inline-components` - Never define subcomponents inside component render bodies.
|
|
84
|
+
|
|
85
|
+
### 6. Rendering Performance (MEDIUM)
|
|
86
|
+
|
|
87
|
+
- `rendering-content-visibility` - Use `content-visibility: auto` for long offscreen lists.
|
|
88
|
+
- `rendering-hoist-jsx` - Extract static JSX elements outside components.
|
|
89
|
+
- `rendering-conditional-render` - Use ternary (`condition ? <Comp /> : null`), not `&&` to avoid 0 rendering.
|
|
90
|
+
- `rendering-usetransition-loading` - Prefer `useTransition` for loading state indicators.
|
|
91
|
+
|
|
92
|
+
### 7. JavaScript Performance (LOW-MEDIUM)
|
|
93
|
+
|
|
94
|
+
- `js-index-maps` - Build `Map` for repeated lookups instead of repeated array searches.
|
|
95
|
+
- `js-cache-property-access` - Cache object properties in tight loops.
|
|
96
|
+
- `js-early-exit` - Return early from functions to avoid nested complexity.
|
|
97
|
+
- `js-hoist-regexp` - Hoist RegExp creation outside loops and functions.
|
|
98
|
+
- `js-set-map-lookups` - Use `Set` / `Map` for O(1) lookups.
|
|
99
|
+
|
|
100
|
+
### 8. Advanced Patterns (LOW)
|
|
101
|
+
|
|
102
|
+
- `advanced-effect-event-deps` - Don't put `useEffectEvent` results in effect deps.
|
|
103
|
+
- `advanced-event-handler-refs` - Store event handlers in refs for stable listener attachments.
|
|
104
|
+
- `advanced-init-once` - Initialize app singletons once per lifecycle.
|
|
105
|
+
|
|
106
|
+
## Code Examples
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
// [GOOD] Parallel server fetching without waterfall
|
|
110
|
+
import { cache } from 'react';
|
|
111
|
+
|
|
112
|
+
export const getUser = cache(async (id: string) => {
|
|
113
|
+
return db.user.findUnique({ where: { id } });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export default async function UserPage({ params }: { params: { id: string } }) {
|
|
117
|
+
// Parallel dispatch
|
|
118
|
+
const userPromise = getUser(params.id);
|
|
119
|
+
const postsPromise = getPosts(params.id);
|
|
120
|
+
|
|
121
|
+
const [user, posts] = await Promise.all([userPromise, postsPromise]);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<main>
|
|
125
|
+
<h1>{user.name}</h1>
|
|
126
|
+
<PostList posts={posts} />
|
|
127
|
+
</main>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Validation Checklist
|
|
133
|
+
|
|
134
|
+
- [ ] All independent async fetches use `Promise.all()` instead of sequential `await`.
|
|
135
|
+
- [ ] Direct imports used instead of barrel file imports for large libraries.
|
|
136
|
+
- [ ] No `useEffect` used for deriving computed state from props or state.
|
|
137
|
+
- [ ] Heavy interactive modals/drawers loaded dynamically via `next/dynamic`.
|
|
138
|
+
- [ ] Server actions perform authentication checks before data mutations.
|
|
139
|
+
- [ ] Zero subcomponents defined inside the body of parent components.
|
|
140
|
+
|
|
141
|
+
## Common Mistakes
|
|
142
|
+
|
|
143
|
+
- Writing sequential `await fetchA(); await fetchB();` creating avoidable network waterfalls.
|
|
144
|
+
- Importing from package root barrel files triggering full bundle inclusion.
|
|
145
|
+
- Setting state inside `useEffect` in response to prop changes.
|
|
146
|
+
- Serializing full database models with sensitive or unused fields to Client Components.
|
|
147
|
+
|
|
148
|
+
## Integration Notes
|
|
149
|
+
|
|
150
|
+
- Pairs with `react` and `nextjs` skills for idiomatic App Router patterns.
|
|
151
|
+
- Complements `performance` for Lighthouse and Core Web Vitals verification.
|
|
152
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: redesign-audit
|
|
3
|
+
description: >
|
|
4
|
+
Audits and upgrades existing web codebases with high-end typography, color, layout, and interaction polish.
|
|
5
|
+
---
|
|
6
|
+
# Redesign Skill & UI Audit
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
A systematic redesign and auditing protocol designed to elevate existing websites, dashboards, and web applications to world-class agency quality. It diagnoses and eradicates generic AI design fingerprints, sloppy typography, inconsistent palettes, and absent interaction states without breaking business logic or underlying component contracts.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- When auditing an existing UI codebase for design quality, responsiveness, or accessibility.
|
|
15
|
+
- When modernizing a legacy application or uplifting generic templates.
|
|
16
|
+
- When tasked to "redesign", "clean up the layout", "audit UI", or "make it look expensive and modern".
|
|
17
|
+
|
|
18
|
+
## Rules & Patterns
|
|
19
|
+
|
|
20
|
+
### 1. Workflow: Scan → Diagnose → Fix
|
|
21
|
+
|
|
22
|
+
1. **Scan:** Read the codebase. Identify the framework, styling method (Tailwind v3/v4, vanilla CSS, CSS Modules), and established design tokens.
|
|
23
|
+
2. **Diagnose:** Run through the design audit categories. Catalog generic patterns, missing states, and optical alignment flaws.
|
|
24
|
+
3. **Fix:** Apply surgical, targeted upgrades working within the existing stack. Do not rewrite from scratch.
|
|
25
|
+
|
|
26
|
+
### 2. Design Audit Categories
|
|
27
|
+
|
|
28
|
+
#### Typography
|
|
29
|
+
|
|
30
|
+
- **Replace Browser Defaults:** Swap generic `Inter`, `Roboto`, or system fonts with expressive typefaces (`Geist`, `Outfit`, `Cabinet Grotesk`, `Satoshi`).
|
|
31
|
+
- **Presence & Scale:** Increase display text size, tighten letter-spacing (`-0.02em` to `-0.04em`), reduce line-height on headlines.
|
|
32
|
+
- **Reading Comfort:** Limit body text to 65 characters per line (`max-w-prose`), increase line-height to 1.6.
|
|
33
|
+
- **Figures:** Enable tabular figures (`font-variant-numeric: tabular-nums`) for numbers in tables and data readouts.
|
|
34
|
+
- **Orphan Prevention:** Apply `text-wrap: balance` on headlines and `text-wrap: pretty` on paragraphs.
|
|
35
|
+
|
|
36
|
+
#### Color and Surfaces
|
|
37
|
+
|
|
38
|
+
- **No Pure Black Backgrounds:** Replace `#000000` with tinted dark charcoal (`#0A0A0A`, `#121212`).
|
|
39
|
+
- **Desaturate Accents:** Keep accent saturation below 80% so it blends harmoniously with neutrals.
|
|
40
|
+
- **Single Accent Color:** Commit to one dominant accent hue; remove conflicting secondary tints.
|
|
41
|
+
- **Tinted Shadows:** Tint shadows to match the background hue rather than harsh black opacity.
|
|
42
|
+
- **Background Depth:** Prevent sterile flat sections by layering subtle noise overlays, ambient gradients, or masked imagery.
|
|
43
|
+
|
|
44
|
+
#### Layout and Space
|
|
45
|
+
|
|
46
|
+
- **Asymmetry & Bento Grids:** Break repetitive 3-column Bootstrap grids with asymmetrical spans or offset cards.
|
|
47
|
+
- **Mobile Viewport Bug Fix:** Never use `height: 100vh`; always use `min-height: 100dvh`.
|
|
48
|
+
- **Vertical Alignment:** Pin action buttons to the bottom of card groups (`mt-auto` or grid alignment) to maintain horizontal baseline harmony across differing text heights.
|
|
49
|
+
- **Optical Centering:** Adjust icons, badges, and play buttons optically by 1-2px rather than relying solely on pure mathematical centering.
|
|
50
|
+
|
|
51
|
+
#### Interactivity and States
|
|
52
|
+
|
|
53
|
+
- **Interactive Feedback:** Add 200-300ms transitions, distinct hover shifts, and physical active presses (`scale(0.98)`).
|
|
54
|
+
- **Visible Focus Rings:** Mandatory `:focus-visible` styling for keyboard navigation.
|
|
55
|
+
- **States Completeness:** Always provide designed skeleton loaders, empty states, and inline error messages.
|
|
56
|
+
|
|
57
|
+
#### Content & Code Quality
|
|
58
|
+
|
|
59
|
+
- **Eradicate AI Clichés:** Remove buzzwords ("Elevate", "Seamless", "Unleash", "Next-Gen") and placeholder latin text.
|
|
60
|
+
- **Semantic HTML:** Replace nested div containers with `<nav>`, `<main>`, `<article>`, `<section>`, `<aside>`.
|
|
61
|
+
- **Relative Units:** Use `rem`, `%`, and CSS Grid rather than hardcoded pixel widths.
|
|
62
|
+
|
|
63
|
+
### 3. Fix Priority
|
|
64
|
+
|
|
65
|
+
1. **Font Swap:** Biggest instant aesthetic elevation with lowest regression risk.
|
|
66
|
+
2. **Palette Cleanup:** Eliminate clashing or oversaturated colors.
|
|
67
|
+
3. **States & Feedback:** Add hover, active, focus, loading, and empty states.
|
|
68
|
+
4. **Layout & Alignment:** Fix container widths, baseline alignment, and mobile viewport heights.
|
|
69
|
+
5. **Component Polish:** Replace generic cards and accordion boxes with modern minimal equivalents.
|
|
70
|
+
|
|
71
|
+
## Code Examples
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
// [BEFORE] Generic, misaligned card with generic shadow
|
|
75
|
+
<div className="bg-white border rounded shadow p-4">
|
|
76
|
+
<h2>{title}</h2>
|
|
77
|
+
<p>{desc}</p>
|
|
78
|
+
<button className="bg-blue-500 text-white p-2">Click</button>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
// [AFTER] Polished card with optical baseline alignment, tinted surface, and micro-interaction
|
|
82
|
+
<div className="flex flex-col bg-[#FFFFFF] dark:bg-[#121212] border border-black/5 dark:border-white/10 rounded-2xl p-6 hover:shadow-[0_4px_20px_rgba(0,0,0,0.04)] transition-all duration-200">
|
|
83
|
+
<h3 className="font-semibold text-lg tracking-tight text-neutral-900 dark:text-neutral-100 text-balance mb-2">
|
|
84
|
+
{title}
|
|
85
|
+
</h3>
|
|
86
|
+
<p className="text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed text-pretty mb-6">
|
|
87
|
+
{desc}
|
|
88
|
+
</p>
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
className="mt-auto inline-flex items-center justify-center font-medium text-sm px-4 py-2.5 rounded-xl bg-neutral-900 dark:bg-neutral-100 text-white dark:text-black hover:bg-neutral-800 active:scale-[0.98] transition-transform duration-150 focus-visible:ring-2 focus-visible:ring-neutral-400"
|
|
92
|
+
>
|
|
93
|
+
Continue
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Validation Checklist
|
|
99
|
+
|
|
100
|
+
- [ ] All headings have `text-wrap: balance` and appropriate negative letter tracking.
|
|
101
|
+
- [ ] No pure black `#000000` backgrounds or oversaturated accent colors (>80% saturation).
|
|
102
|
+
- [ ] All interactive elements include `:hover`, `:active`, and `:focus-visible` styles.
|
|
103
|
+
- [ ] Cards in side-by-side grids align primary CTA buttons along the same bottom baseline.
|
|
104
|
+
- [ ] Viewport containers use `100dvh` instead of `100vh`.
|
|
105
|
+
- [ ] All lists, tables, and feeds have a designed empty state.
|
|
106
|
+
|
|
107
|
+
## Common Mistakes
|
|
108
|
+
|
|
109
|
+
- Rewriting components from scratch and breaking existing prop contracts or unit tests.
|
|
110
|
+
- Forcing full-width sections without `max-w` constraints on ultra-wide screens.
|
|
111
|
+
- Leaving action buttons at random heights inside differing text content cards.
|
|
112
|
+
- Introducing external UI libraries without checking existing `package.json` dependencies.
|
|
113
|
+
|
|
114
|
+
## Integration Notes
|
|
115
|
+
|
|
116
|
+
- Complements `impeccable-design` for hard 50-rule QA verification.
|
|
117
|
+
- Works alongside `ui-ux-pro` for token generation and color theory.
|
|
118
|
+
|