
server-components
Enforces project server component conventions for async data fetching, caching integration, streamin
提供方 JasonPaff|开源
Server Components Skill
Purpose
This skill provides server-specific React conventions that extend the base react-coding-conventions skill. It covers patterns unique to server components: async data fetching, caching, streaming, and metadata generation.
When to Use This Skill
Use this skill in the following scenarios:
- Creating page.tsx, layout.tsx, loading.tsx, or error.tsx files
- Implementing async server components
- Adding Suspense streaming or skeleton components
- Generating page metadata
- Fetching data in server components through facades
Important: This skill should activate automatically when server component work is detected.
Prerequisite Skills
This skill REQUIRES loading these skills FIRST:
- react-coding-conventions - Base React patterns
- ui-components - UI component patterns
- caching - Cache service patterns (for data fetching)
How to Use This Skill
1. Load Prerequisites and Reference
Before creating or modifying server components:
1. Read .claude/skills/react-coding-conventions/references/React-Coding-Conventions.md
2. Read .claude/skills/ui-components/references/UI-Components-Conventions.md
3. Read .claude/skills/caching/references/Caching-Conventions.md
4. Read .claude/skills/server-components/references/Server-Components-Conventions.md
2. Apply Server Component Patterns
Async Component Structure:
- Use async arrow functions or async function declarations
- Add
import 'server-only'guard for server-only code - Fetch data through facades with caching
- Use Promise.all for parallel data fetching
Authentication:
- Use
getUserIdAsync()for optional user auth - Use
getRequiredUserIdAsync()for required user auth (redirect if unauthenticated or user not found) - Use
checkIsOwnerAsync()for ownership checks
Streaming with Suspense:
- Wrap async children in
<Suspense fallback={<Skeleton />}> - Create corresponding skeleton components
- Use error boundaries for resilience
Metadata Generation:
- Export
generateMetadatafor pages - Use
generatePageMetadata()utility - Include JSON-LD structured data
ISR Configuration:
- Export
revalidateconstant when appropriate
3. Automatic Convention Enforcement
After generating code:
- Scan for violations against server component patterns
- Fix automatically without asking permission
- Verify completeness before presenting to user
4. Reporting
Provide a brief summary of conventions applied:
Server component conventions enforced:
- Added 'server-only' import guard
- Used async arrow function pattern
- Wrapped children in Suspense with skeleton
- Added generateMetadata for SEO
- Used CacheService for data fetching
Component Naming Conventions
*Asyncsuffix for async data-fetching components*Serversuffix for server-only orchestration*Skeletonsuffix for loading states
File Patterns
This skill handles:
src/app/**/page.tsxsrc/app/**/layout.tsxsrc/app/**/loading.tsxsrc/app/**/error.tsxsrc/app/**/components/async/*.tsxsrc/app/**/components/*-async.tsxsrc/app/**/components/*-server.tsx*-skeleton.tsx
Workflow Summary
1. Detect server component work (page.tsx, async component, data fetch)
2. Load prerequisites: react-coding-conventions, ui-components, caching
3. Load references/Server-Components-Conventions.md
4. Generate/modify code following ALL conventions
5. Scan for violations
6. Auto-fix violations
7. Report fixes applied