Server Dedup Props
Source: .agents/references/coding-standard/vercel-react-best-practices/rules/server-dedup-props.md
Metadata
- title: Avoid Duplicate Fields in Page Props
- impact: LOW
- impactDescription: reduces network payload by avoiding duplicate serialization
- tags: server, pages-router, serialization, props, getStaticProps, getServerSideProps
Content
This repo: Pages Router only — avoid returning overlapping or derived copies of the same data from
getStaticProps/getServerSideProps. Do expensive transforms client-side when the page can derive them from one source.
Avoid Duplicate Fields in Page Props
Impact: LOW (reduces payload size in __NEXT_DATA__)
Each distinct value in props is serialized. Returning the same logical data twice (raw array + sorted copy, full object + single field) doubles payload size.
Incorrect (duplicates array in props):
export const getServerSideProps: GetServerSideProps = async () => {
const usernames = await fetchUsernames()
return {
props: {
usernames,
usernamesOrdered: usernames.toSorted()
}
}
}
Correct (send once; sort on client):
export const getServerSideProps: GetServerSideProps = async () => {
const usernames = await fetchUsernames()
return { props: { usernames } }
}
// Page: derive sorted list during render or useMemo
function Page({ usernames }: { usernames: string[] }) {
const sorted = useMemo(() => [...usernames].sort(), [usernames])
// ...
}
Operations that commonly duplicate payload when returned twice:
- Arrays:
.toSorted(),.filter(),.map(),.slice(),[...arr] - Objects:
{...obj},Object.assign(),structuredClone()
More examples:
// Avoid
return { props: { users, activeUsers: users.filter((u) => u.active) } }
return { props: { product, productName: product.name } } }
// Prefer
return { props: { users } }
return { props: { product } }
// Filter or destructure in the page component
Exception: Return derived data from the data function when the transform is expensive and the client cannot reuse the original efficiently.