feat(error-handling): add global error boundary for root layout crashes#179
Merged
mikewheeleer merged 3 commits intoJun 26, 2026
Conversation
Contributor
|
great stuff — merging this 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
src/app/global-error.tsx— the top-level error boundary Next.js requires to catch exceptions thrown inside the root layout itself (Header,Footer,ToastProviderinlayout.tsx). Without this file, a root-layout crash produces an unstyled white screen with no recovery path.closes #83
Problem
The app had a route-level
src/app/error.tsxboundary, but noglobal-error.tsx. Any exception thrown in the root layout escaped all boundaries and gave the user an unrecoverable blank screen.Changes
src/app/global-error.tsx(new)"use client"component as required by Next.js<html>/<body>shell so it works without the failed layout chromerole="alert"+aria-live="assertive"on<main>for immediate screen-reader announcementerror.messagewith a safe fallback ("An unexpected error occurred.") when the message is emptyerror.digestas a Reference ID for support correlation — conditionally rendered only when presentconsole.erroron mount (drop-in point for an observability service like Sentry)reset()to attempt recoverysrc/app/global-error.test.tsx(new)19 tests across 6 suites — 100% coverage (statements, branches, functions, lines):
role="alert",aria-live,id="main-content"error.digestundefinedreset()called once on click, called again on repeat clicks<html>and<body>declared in source; no Header/Footer/ToastProvider dependencyconsole.errorcalled on mount with the errorREADME.md(updated)error.tsx) and global (global-error.tsx) boundaries, their responsibilities, and design decisionsglobal-error.tsxentry to the project structure treeTest output
Checklist
npm run lint— cleannpm run typecheck— cleannpm test(new file) — 19/19 pass, 100% coveragerole="alert",aria-live="assertive", keyboard-focusable reset button with visible focus ring