Performance: ErrorBoundary component
ErrorBoundary affects user experience by preventing full page crashes and controlling error rendering, impacting interaction responsiveness and visual stability.
import { useCatch } from '@remix-run/react'; export function ErrorBoundary() { const caught = useCatch(); return ( <div role="alert" aria-live="assertive"> <h1>Error: {caught.status}</h1> <p>{caught.statusText}</p> </div> ); } export default function App() { return <ErrorBoundary />; }
export function ErrorBoundary() {
throw new Error('Crash!');
}
export default function App() {
return <ErrorBoundary />;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No ErrorBoundary (app crash) | Full DOM reload | Multiple reflows | High paint cost | [X] Bad |
| ErrorBoundary with simple fallback UI | Minimal DOM update | Single reflow | Low paint cost | [OK] Good |
ErrorBoundary component in Remix?ErrorBoundary component in Remix?error prop with error details, so the parameter must be { error }.error.message to show the error text.{ error } prop and show error.message [OK]ErrorBoundary component, what will be rendered if an error with message "Failed to load" occurs?export function ErrorBoundary({ error }) {
return (
<div role="alert">
<h2>Oops!</h2>
<p>{error.message}</p>
</div>
);
}{error.message} inside a paragraph, so the actual error message will appear.ErrorBoundary component code?export function ErrorBoundary(error) {
return <div>Error: {error.message}</div>;
}{ error }, not a plain variable.error directly means it is the whole props object, so error.message will be undefined or cause error.ErrorBoundary that shows a custom message for network errors and a generic message for others. Which code correctly implements this behavior?export function ErrorBoundary({ error }) {
if (error.message.includes('Network')) {
return <div>Network error occurred. Please try again.</div>;
}
return <div>Something went wrong.</div>;
}error.message contains 'Network' to show a specific message.Pass the test and this pattern moves unknown