'use client' на вершине page тянет весь subtree в bundle; правильно — server page + client leaf или children-as-prop.
Пример
// ❌ 'use client' at the top pulls the ENTIRE tree — including the data-heavy// and its dependencies — into the browser bundle.'use client';
import { Feed } from'./feed';
exportdefaultfunctionPage() {
const [open, setOpen] = useState(false);
return<> setOpen(true)}/>;
}
// ✅ Keep the page a Server Component. Isolate interactivity in a leaf.import { Feed } from'./feed'; // stays on the server, ships 0 JSimport { Toggle } from'./toggle'; // the ONLY client componentexportdefaultfunctionPage() {
return<>;
}
// ✅ The children-as-prop pattern: a client shell wrapping server content'use client';
exportfunctionPanel({ children }: { children: React.ReactNode }) {
const [open, setOpen] = useState(true);
return open ? {children} : null; // children can be a Server Component!
}
// Used from a server component:
Итог
Push 'use client' к листьям; composition через children — server content без client bundle bloat.
Next.js: Server vs Client Components — пример кода · Sobeso