Performance: Client-side session access
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by how session data is accessed and rendered on the client side.
import { useSession } from 'next-auth/react'; export default function Profile() { const { data: session } = useSession({ required: false }); return <p>Welcome, {session?.user?.name ?? 'Guest'}</p>; }
import { useSession } from 'next-auth/react'; export default function Profile() { const { data: session, status } = useSession(); if (status === 'loading') return <p>Loading...</p>; return <p>Welcome, {session.user.name}</p>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking session fetch with loading UI | Moderate (conditional DOM nodes) | Multiple reflows due to content shift | High paint cost on update | [X] Bad |
| Non-blocking session fetch with fallback UI | Low (static DOM initially) | Single reflow on update | Low paint cost | [OK] Good |