Performance: Global-error.tsx for root errors
This affects the page's error handling responsiveness and visual stability during root-level errors.
Jump into concepts and practice - no test required
export default function GlobalError({ error }) { return ( <main role="alert" aria-live="assertive" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: '100vh' }}> <section> <h1>Something went wrong</h1> <p>{error.message}</p> </section> </main> ); }
export default function GlobalError({ error }) { return <div style={{ minHeight: '100vh' }}>{error.message}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline styled error div with dynamic height | Low (few nodes) | Multiple reflows due to dynamic height | Medium paint cost | [X] Bad |
| Semantic main and section with fixed flex layout | Low (few nodes) | Single reflow with fixed layout | Low paint cost | [OK] Good |
Global-error.tsx file in a Next.js app?GlobalError component in Global-error.tsx using React functional components in Next.js?{ error, reset } for Global-error.tsx.Global-error.tsx snippet, what will be rendered when an error with message "Network failure" occurs?export default function GlobalError({ error, reset }) {
return (
Oops!
{error.message}
Try again
);
}<main role="alert"> with a heading, paragraph showing error.message, and a button with text "Try again".Global-error.tsx component code:export default function GlobalError({ error, reset }) {
return (
Error!
{error}
Retry
);
}error prop is an object; displaying it directly will show [object Object], not the message.error.message to display the actual error text.error prop is used directly instead of error.message -> Option DGlobal-error.tsx component. Which change best helps screen reader users understand the error state?role="alert" attribute tells screen readers to announce the content immediately, which is important for error messages.role="alert" to the main container to announce the error immediately -> Option C