Performance: CatchBoundary for expected errors
CatchBoundary affects how error UI is rendered without full page reload, impacting interaction responsiveness and visual stability.
import { useCatch } from '@remix-run/react'; export function CatchBoundary() { let caught = useCatch(); return <div role="alert">Error {caught.status}: {caught.statusText}</div>; } // Loader throws expected error as above // CatchBoundary renders error inline
export function loader() {
throw new Response('Not Found', { status: 404 });
}
// No CatchBoundary component defined
// The app falls back to ErrorBoundary or default error UI| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No CatchBoundary (fallback) | High (full DOM rebuild) | Multiple reflows | High paint cost | [X] Bad |
| CatchBoundary inline render | Low (partial DOM update) | Single reflow | Low paint cost | [OK] Good |
CatchBoundary in Remix Framework?CatchBoundary component?useCatch() to get error details inside CatchBoundary.useError(), useBoundary(), or useErrorBoundary() do not exist in Remix for this purpose.export function CatchBoundary() {
const caught = useCatch();
return (
<div>
<h1>Error {caught.status}</h1>
<p>{caught.statusText}</p>
</div>
);
}Not Found
.export function CatchBoundary() {
const caught = useCatch;
return (
<div>Error: {caught.status}</div>
);
}const caught = useCatch; without parentheses, so useCatch is not called.export function CatchBoundary() {
const caught = useCatch();
if (caught.status === 401) {
return <div>Please log in to access this page.</div>;
}
return <div>Error {caught.status}</div>;
}
B) export function CatchBoundary() {
const caught = useCatch();
if (caught.status === 403) {
return <div>Please log in to access this page.</div>;
}
return <div>Error {caught.status}</div>;
}
C) export function CatchBoundary() {
const caught = useCatch();
if (caught.status === 401) {
return <div>Access denied.</div>;
}
return <div>Error {caught.status}</div>;
}
D) export function CatchBoundary() {
const caught = useCatch();
if (caught.status === 401) {
return <div>Error 401 occurred.</div>;
}
return <div>Please log in to access this page.</div>;
}Pass the test and this pattern moves unknown