知识库首页 知识库-世界 server-serialization.md

server serialization

本地来源:Knowledge/World/项目/Practice/Claude-Skills/vercel-react-best-practices/rules/server-serialization.md


title: Minimize Serialization at RSC Boundaries impact: HIGH impactDescription: reduces data transfer size tags: server, rsc, serialization, props


Minimize Serialization at RSC Boundaries

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.

Incorrect (serializes all 50 fields):

async function Page() {
  const user = await fetchUser()  // 50 fields
  return <Profile user={user} />
}

'use client'
function Profile({ user }: { user: User }) {
  return <div>{user.name}</div>  // uses 1 field
}

Correct (serializes only 1 field):

async function Page() {
  const user = await fetchUser()
  return <Profile name={user.name} />
}

'use client'
function Profile({ name }: { name: string }) {
  return <div>{name}</div>
}

本文档为站内渲染。原始文件本地路径:saas/source/knowledge-world/Knowledge-World-项目-Practice-Claude-Skills-vercel-react-best--405754.md(仅本地保留,不入库不部署)