When a React component throws during render, the framework looks for the nearest error.tsx and, failing that, falls back to global-error.tsx. The second one replaces the whole document. What the visitor sees depends entirely on which of the two caught it, and in our app that turned out to be worth designing on purpose.
Three layers
global-error.tsx is the last resort. It has to render its own <html> and <body>, because by the time it runs the root layout is gone: no theme script, no fonts, no providers. Ours is a heading, a sentence and a "Try again" button in inline styles. It reports to Sentry with a dynamic import() inside an effect, so the SDK is not pulled into the initial bundle of every page just to serve a screen almost nobody sees.
app/error.tsx exists to make sure nobody reaches the layer above. Its own comment says it plainly: without it, any render error not covered by a nearer boundary escalates to global-error, which is the right answer for a broken root layout and the wrong one for a broken marketing page. This boundary sits inside the layout, so the theme, fonts and providers all survive.
A shared RouteErrorFallback is the body that four of our six segment boundaries render. There are six error.tsx files in total (root, games, dashboard, interview, exercises, admin), and one component with a handful of props means they cannot drift into six different apologies.
The header problem
The detail I like most is in the fallback's comment. An error.tsx replaces the page below the nearest layout. Several of our public segments have no layout.tsx: each page renders the site header itself. So when the boundary trips, the header goes down with the page, and the visitor is left on a bare screen with no navigation.
The fallback therefore renders the header itself, which works because the header is a client component and a client boundary can import it. The footer is deliberately left out: it is a server component whose link tree would be dragged into the client bundle for a screen that exists to say one sentence.
One segment turns the header off. The exercises area is signed-in only, and the public header offers "Sign in" and "Sign up", which is the wrong thing to show someone who is already signed in and was halfway through an exercise. So the prop is withPublicHeader={false}, and with no fixed header the top padding shrinks too.
Two quieter rules
In production the raw error message is never shown. Next.js has already replaced a server error's message with a generic string, and showing a client error's text to a candidate is noise at best and an internals leak at worst. What ships instead is the digest, printed as "Reference: ...", because that is the value support can match against the logged exception. In development the message is shown, and the error goes to the console instead of Sentry.
And the layout notes in the comment are the kind that only exist because someone got it wrong once: min-h-dvh rather than min-h-screen, because on a phone 100vh is the viewport with the browser bars hidden and pushes content under the address bar; and no card with borders, because a global stylesheet rule strips borders from anything with bg-card in its class, so the card would render flat anyway.
The page that does not follow its own rule
That dvh comment is a good rule, so I checked who follows it. RouteErrorFallback does. The 404 page does not: app/not-found.tsx wraps itself in min-h-screen, and so does the unsubscribe page. They are the same kind of short, centred, one-message screen, written by the same hand at a different time, and one of them carries a comment explaining a mobile bug that the others still have. Nothing flags it, because both look right on a desktop.
See it
Open a URL that does not exist, such as this one. You get a real 404 status, the title "Page Not Found | CogniPrep", and a noindex, follow robots tag, so the page is not indexed but the links on it are still followed. The header and footer are the normal ones, with three buttons: home, browse games, and get help. Do the same on your phone and compare how the content sits against the bottom bar with a page that follows the dvh rule.
I cannot show you the error boundaries themselves, because making production throw to demonstrate one would be rude, so the claims about them come from the source and its comments.
CogniPrep is a practice site for employer assessments, and the homepage is the place to start.