Skills included: - pr-reviewer: Adapted for Gitea/GitHub via platform-aware scripts (dropped fetch_pr_data.py and add_inline_comment.py, kept generate_review_files.py) - code-review-excellence: Methodology and checklists (React, TS, Python, etc.) - vercel-react-best-practices: 57 rules for React/Next.js performance - tailwind-design-system: Tailwind CSS v4 patterns, CVA, design tokens New shell scripts added to ~/.claude/scripts/git/: - pr-diff.sh: Get PR diff (GitHub gh / Gitea API) - pr-metadata.sh: Get PR metadata as normalized JSON Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
Markdown
39 lines
1.1 KiB
Markdown
---
|
||
title: Prevent Waterfall Chains in API Routes
|
||
impact: CRITICAL
|
||
impactDescription: 2-10× improvement
|
||
tags: api-routes, server-actions, waterfalls, parallelization
|
||
---
|
||
|
||
## Prevent Waterfall Chains in API Routes
|
||
|
||
In API routes and Server Actions, start independent operations immediately, even if you don't await them yet.
|
||
|
||
**Incorrect (config waits for auth, data waits for both):**
|
||
|
||
```typescript
|
||
export async function GET(request: Request) {
|
||
const session = await auth()
|
||
const config = await fetchConfig()
|
||
const data = await fetchData(session.user.id)
|
||
return Response.json({ data, config })
|
||
}
|
||
```
|
||
|
||
**Correct (auth and config start immediately):**
|
||
|
||
```typescript
|
||
export async function GET(request: Request) {
|
||
const sessionPromise = auth()
|
||
const configPromise = fetchConfig()
|
||
const session = await sessionPromise
|
||
const [config, data] = await Promise.all([
|
||
configPromise,
|
||
fetchData(session.user.id)
|
||
])
|
||
return Response.json({ data, config })
|
||
}
|
||
```
|
||
|
||
For operations with more complex dependency chains, use `better-all` to automatically maximize parallelism (see Dependency-Based Parallelization).
|