Performance: Loading UI with loading.tsx
This affects the perceived page load speed and interaction responsiveness by showing a placeholder UI during data fetching or component loading.
export default function Loading() { return <div aria-busy="true" aria-label="Loading content" style={{fontSize: '1.2rem'}}>Loading...</div>; }
export default function Loading() { return <div>Loading full spinner with heavy SVG and animations</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy animated spinner in loading.tsx | Moderate (multiple nodes) | Multiple reflows due to animation | High paint cost | [X] Bad |
| Simple text or minimal placeholder in loading.tsx | Low (single node) | Single reflow | Low paint cost | [OK] Good |
loading.tsx file in a Next.js app?loading.tsx file is used to display a loading UI automatically during page or component loading.loading.tsx for Next.js?export default function or export default const.Loading...
; } -> Option Cloading.tsx component:export default function Loading() {
return Loading data...;
}div with text 'Loading data...' and accessibility roles.role="status" and aria-live="polite" announce the text to screen readers politely.loading.tsx file is not showing the loading UI as expected:export default function Loading() {
Loading...
}return statement, so nothing is rendered.loading.tsx. Which code snippet correctly implements this?role="status" with aria-live="polite" announces updates politely without interrupting.aria-hidden="true" so screen readers ignore it, focusing on text.div wraps spinner and text properly for screen readers and visual users.Pass the test and this pattern moves unknown