Next.js
next/use-client-at-leaves
Keep App Router pages and layouts Server Components; put 'use client' on the small interactive component they render.
moderatestaticfe-nextjs
Why
'use client' marks a boundary: the file and everything it imports go into the browser bundle. On a page or layout that means the whole route's markup, its helpers and its libraries are downloaded and hydrated, data fetching moves to the client, and the file can no longer export metadata or generateMetadata.
Fix
Remove 'use client' from the page or layout. Move the state, effects and handlers into a component of their own (SearchBox, AddToCartButton) that starts with 'use client', and render it from the server page, passing data as serializable props. Server Components passed as children to a client component stay on the server.
Examples
// bad: app/products/page.tsx
'use client'
export default function Page() { const [q, setQ] = useState(''); return <main>…</main> }
// good: app/products/page.tsx stays a Server Component
export default async function Page() { const products = await getProducts(); return <main><SearchBox /><List items={products} /></main> }Sources
Facts
- Id
next/use-client-at-leaves- Severity
- moderate
- Check
- static checked in the source by
audit - Applies to
jsx- Only in projects with
next- Taught by the skill
fe-nextjsNext.js App Router- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain next/use-client-at-leaves