Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/server-dedup-props.md
1---2title: Avoid Duplicate Serialization in RSC Props3impact: LOW4impactDescription: reduces network payload by avoiding duplicate serialization5tags: server, rsc, serialization, props, client-components6---78## Avoid Duplicate Serialization in RSC Props910**Impact: LOW (reduces network payload by avoiding duplicate serialization)**1112RSC→client serialization deduplicates by object reference, not value. Same reference = serialized once; new reference = serialized again. Do transformations (`.toSorted()`, `.filter()`, `.map()`) in client, not server.1314**Incorrect (duplicates array):**1516```tsx17// RSC: sends 6 strings (2 arrays × 3 items)18<ClientList usernames={usernames} usernamesOrdered={usernames.toSorted()} />19```2021**Correct (sends 3 strings):**2223```tsx24// RSC: send once25<ClientList usernames={usernames} />2627// Client: transform there28'use client'29const sorted = useMemo(() => [...usernames].sort(), [usernames])30```3132**Nested deduplication behavior:**3334Deduplication works recursively. Impact varies by data type:3536- `string[]`, `number[]`, `boolean[]`: **HIGH impact** - array + all primitives fully duplicated37- `object[]`: **LOW impact** - array duplicated, but nested objects deduplicated by reference3839```tsx40// string[] - duplicates everything41usernames={['a','b']} sorted={usernames.toSorted()} // sends 4 strings4243// object[] - duplicates array structure only44users={[{id:1},{id:2}]} sorted={users.toSorted()} // sends 2 arrays + 2 unique objects (not 4)45```4647**Operations breaking deduplication (create new references):**4849- Arrays: `.toSorted()`, `.filter()`, `.map()`, `.slice()`, `[...arr]`50- Objects: `{...obj}`, `Object.assign()`, `structuredClone()`, `JSON.parse(JSON.stringify())`5152**More examples:**5354```tsx55// ❌ Bad56<C users={users} active={users.filter(u => u.active)} />57<C product={product} productName={product.name} />5859// ✅ Good60<C users={users} />61<C product={product} />62// Do filtering/destructuring in client63```6465**Exception:** Pass derived data when transformation is expensive or client doesn't need original.66