返回 AiToEarn
server-serialization.md
1 ---
2 title: Minimize Serialization at RSC Boundaries
3 impact: HIGH
4 impactDescription: reduces data transfer size
5 tags: server, rsc, serialization, props
6 ---
7
8 ## Minimize Serialization at RSC Boundaries
9
10 The React Server/Client boundary serializes all object properties into strings and embeds them in the HTML response and subsequent RSC requests. This serialized data directly impacts page weight and load time, so **size matters a lot**. Only pass fields that the client actually uses.
11
12 **Incorrect (serializes all 50 fields):**
13
14 ```tsx
15 async function Page() {
16 const user = await fetchUser() // 50 fields
17 return <Profile user={user} />
18 }
19
20 'use client'
21 function Profile({ user }: { user: User }) {
22 return <div>{user.name}</div> // uses 1 field
23 }
24 ```
25
26 **Correct (serializes only 1 field):**
27
28 ```tsx
29 async function Page() {
30 const user = await fetchUser()
31 return <Profile name={user.name} />
32 }
33
34 'use client'
35 function Profile({ name }: { name: string }) {
36 return <div>{name}</div>
37 }
38 ```
39
39 lines MARKDOWN