| 1 | --- |
| 2 | title: Avoid Duplicate Serialization in RSC Props |
| 3 | impact: LOW |
| 4 | impactDescription: reduces network payload by avoiding duplicate serialization |
| 5 | tags: server, rsc, serialization, props, client-components |
| 6 | --- |
| 7 | |
| 8 | ## Avoid Duplicate Serialization in RSC Props |
| 9 | |
| 10 | **Impact: LOW (reduces network payload by avoiding duplicate serialization)** |
| 11 | |
| 12 | RSC→client serialization deduplicates by object reference, not value. Same reference = serialized once; new reference = serialized again. Do transformations (`.toSorted()`, `.filter()`, |
| 13 | |
| 14 | **Incorrect (duplicates array):** |
| 15 | |
| 16 | ```tsx |
| 17 | // RSC: sends 6 strings (2 arrays × 3 items) |
| 18 | <ClientList usernames={ |
| 19 | ``` |
| 20 | |
| 21 | **Correct (sends 3 strings):** |
| 22 | |
| 23 | ```tsx |
| 24 | // RSC: send once |
| 25 | <ClientList usernames={ |
| 26 | |
| 27 | // Client: transform there |
| 28 | ("use client"); |
| 29 | const sorted = useMemo |
| 30 | ``` |
| 31 | |
| 32 | **Nested deduplication behavior:** |
| 33 | |
| 34 | Deduplication works recursively. Impact varies by data type: |
| 35 | |
| 36 | - `string[]`, `number[]`, |
| 37 | - `object[]`: **LOW impact |
| 38 | |
| 39 | ```tsx |
| 40 | // string[] - duplicates everything |
| 41 | usernames={['a', |
| 42 | |
| 43 | // object[] - duplicates array structure only |
| 44 | users={[{id:1},{id |
| 45 | ``` |
| 46 | |
| 47 | **Operations breaking deduplication (create new references):** |
| 48 | |
| 49 | - Arrays: `.toSorted()`, `.filter()`, |
| 50 | - Objects: `{...obj}`, `Object.assign()`, |
| 51 | |
| 52 | **More examples:** |
| 53 | |
| 54 | ```tsx |
| 55 | // ❌ Bad |
| 56 | <C users={ |
| 57 | <C product={ |
| 58 | |
| 59 | // ✅ Good |
| 60 | <C users={ |
| 61 | <C product={ |
| 62 | // Do filtering/destructuring in client |
| 63 | ``` |
| 64 | |
| 65 | **Exception:** Pass derived data when transformation is expensive or client doesn't need original. |