Performance: Role-based access patterns
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by controlling which components and data are loaded based on user roles.
export default function Page({ user }) { if (user.role === 'admin') { return <AdminComponent /> } else if (user.role === 'editor') { return <EditorComponent /> } else { return <CommonComponent /> } }
export default function Page({ user }) { return ( <div> <button>Common Action</button> <button style={{ display: user.role === 'admin' ? 'block' : 'none' }}>Admin Action</button> <button style={{ display: user.role === 'editor' ? 'block' : 'none' }}>Editor Action</button> </div> ) }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Render all role UI elements with conditional display | High (many hidden nodes) | Multiple reflows due to style changes | High paint cost for hidden elements | [X] Bad |
| Render only role-specific components | Low (minimal nodes) | Single reflow | Low paint cost | [OK] Good |
| Fetch all role data regardless of user | N/A | N/A | Blocks rendering longer | [X] Bad |
| Fetch only role-specific data | N/A | N/A | Faster rendering, smaller payload | [OK] Good |