Performance: Fallback UI patterns
MEDIUM IMPACT
Fallback UI patterns affect the perceived loading speed and interaction responsiveness by controlling what the user sees during data fetching or lazy loading.
function MyComponent() { const [data, setData] = React.useState(null); React.useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); if (!data) { return <div aria-busy="true" aria-label="Loading content" style={{width: '100%', height: '1rem', backgroundColor: '#eee'}}></div>; } return <div>{data.content}</div>; }
function MyComponent() { const [data, setData] = React.useState(null); React.useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); if (!data) { return <div style={{fontSize: '2rem', fontWeight: 'bold'}}>Loading, please wait...</div>; } return <div>{data.content}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy styled fallback UI | Moderate DOM nodes | Multiple reflows due to size changes | High paint cost from complex styles | [X] Bad |
| Simple fixed-size placeholder fallback | Minimal DOM nodes | Single reflow with fixed size | Low paint cost with simple styles | [OK] Good |