- docs/agent/external: Vercel react-best-practices and composition-patterns (MIT), Addy Osmani accessibility (MIT), Anthropic frontend-design (Apache-2.0), official Payload skill at v3.92.1 (MIT) — text only, each with its licence, SOURCE.md (repo, commit) and an override note in front of the SKILL.md (ipal-kit first, Payload fetching over swr, DESIGN.md tokens, Payload 3 not 4); manifest.json with sha256 per file - scripts/vendor-external-skills.mjs (maintainer, not shipped): fetches by full commit SHA only, rejects non-text or executable files, regenerates the manifest; --check verifies it - ipal-skills --external [names]: copies ext-* after checking every file against the manifest, downloads nothing, never touches ext-* folders without ipal-kit's SOURCE.md, removes only retired ones it installed; an unknown name stops the run before anything is copied - AGENT.md §14, ipal-setup stage 2 (optional step), README: usage, overrides, how to update the pins - test/externalSkills.test.ts: pins are SHAs, no branch fetch, checksums, text only, licences, override note, installer leaves other folders alone Co-Authored-By: Claude Opus 5.5 <[email protected]>
57 lines
1.1 KiB
Markdown
57 lines
1.1 KiB
Markdown
---
|
|
title: Use SWR for Automatic Deduplication
|
|
impact: MEDIUM-HIGH
|
|
impactDescription: automatic deduplication
|
|
tags: client, swr, deduplication, data-fetching
|
|
---
|
|
|
|
## Use SWR for Automatic Deduplication
|
|
|
|
SWR enables request deduplication, caching, and revalidation across component instances.
|
|
|
|
**Incorrect (no deduplication, each instance fetches):**
|
|
|
|
```tsx
|
|
function UserList() {
|
|
const [users, setUsers] = useState([])
|
|
useEffect(() => {
|
|
fetch('/api/users')
|
|
.then(r => r.json())
|
|
.then(setUsers)
|
|
}, [])
|
|
}
|
|
```
|
|
|
|
**Correct (multiple instances share one request):**
|
|
|
|
```tsx
|
|
import useSWR from 'swr'
|
|
|
|
function UserList() {
|
|
const { data: users } = useSWR('/api/users', fetcher)
|
|
}
|
|
```
|
|
|
|
**For immutable data:**
|
|
|
|
```tsx
|
|
import { useImmutableSWR } from '@/lib/swr'
|
|
|
|
function StaticContent() {
|
|
const { data } = useImmutableSWR('/api/config', fetcher)
|
|
}
|
|
```
|
|
|
|
**For mutations:**
|
|
|
|
```tsx
|
|
import { useSWRMutation } from 'swr/mutation'
|
|
|
|
function UpdateButton() {
|
|
const { trigger } = useSWRMutation('/api/user', updateUser)
|
|
return <button onClick={() => trigger()}>Update</button>
|
|
}
|
|
```
|
|
|
|
Reference: [https://swr.vercel.app](https://swr.vercel.app)
|