Skip to content

Error page

The page a site's root ErrorBoundary shows for 404, 410 and 500, in plain words.

<div data-mount="not-found"></div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/error-page.css";

Usage

import { ErrorPage, errorTitle } from "capsomer/react/error-page";
import "capsomer/empty.css";
import "capsomer/error-page.css";

export function meta({ error }: Route.MetaArgs) {
  return error ? [{ title: errorTitle(error, SITE.name) }] : [];
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
  return <ErrorPage error={error} home="/" siteHeader={<SiteHeader />} siteFooter={<SiteFooter />} dev={import.meta.env.DEV} />;
}
<meta name="robots" content="noindex">
[the site header, with its skip link]
<main id="main" tabindex="-1" class="cap-error-page" data-status="404">
  <div class="cap-empty" data-kind="failed" role="alert">
    <div class="cap-empty-header">
      <h1 class="cap-empty-title">[critical glyph]Page not found</h1>
      <p class="cap-empty-text">There is nothing at this address. Check it for a typo, or start again from the home page.</p>
    </div>
    <div class="cap-empty-content"><a class="cap-btn" data-variant="primary" href="/">Go to the home page</a></div>
  </div>
  [children]
</main>
[the site footer]
<main id="main" tabindex="-1" class="cap-error-page" data-status="signed-out">
  <div class="cap-empty" data-kind="nothing-yet" role="status">
    <div class="cap-empty-header">
      <h1 class="cap-empty-title">Signed out</h1>
      <p class="cap-empty-text">You signed out of Example in this browser.</p>
    </div>
    <div class="cap-empty-content"><a class="cap-btn" data-variant="primary" href="/sign-in">Sign in again</a></div>
  </div>
</main>
<main id="main" tabindex="-1" class="cap-error-page" data-status="410">
  <div class="cap-empty" data-kind="nothing-yet">
    <div class="cap-empty-header">
      <h1 class="cap-empty-title">This page is gone</h1>
      <p class="cap-empty-text">It was taken down on purpose.</p>
    </div>
    <div class="cap-empty-content"><a class="cap-btn" data-variant="primary" href="/blog">Read the blog</a></div>
  </div>
</main>

Examples

410: taken down on purpose

<div data-mount="gone"></div>

410 with its one way out and the site's own sentence

<div data-mount="gone-to"></div>

404 with a second way out

<div data-mount="actions"></div>

404 under a site's own title band

<div data-mount="hero"></div>

Signed out by choice, behind Access

<div data-mount="signed-out"></div>

The session ended on its own

<div data-mount="session-ended"></div>

500: something went wrong, with Try again

<div data-mount="server"></div>

503: the database is down, with Try again

<div data-mount="database"></div>

Development: the thrown error's message and its stack

<div data-mount="dev"></div>

Phone: 404

<div data-mount="not-found"></div>

API reference

ErrorPage

PropTypeRequiredDoes
errorunknownYesThe ErrorBoundary's error (Route.ErrorBoundaryProps["error"]).
homestringYesThe home page's address, for the way out.
siteHeaderReactNodeThe site's header, so its skip link and banner landmark stay on the error page. It must read no loader data: on the error path there is none.
siteFooterReactNodeThe site's footer (the contentinfo landmark), under the same condition.
childrenReactNodeUnder the message, inside main: a search form, the site's most read pages.
devbooleanDevelopment only: the thrown error's message and stack are shown. Pass import.meta.env.DEV; off by default, so production never shows a stack.
mainIdstringThe main region's id, the skip link's target. Default "main".
classNamestringA class for main beside cap-error-page, for the site's own page frame.
titlestringThe site's own words, in place of errorWords' for this error: a site whose copy is edited content (julieedwards.info's 404 is Carrel copy in D1) passes it here.
textstring
homeLabelstringThe home link's words. Default "Go to the home page".
homeIconReactNodeAn icon after the home link's words, for a site whose buttons that go somewhere carry one (bsw's arrow): an svg with data-icon="end" and aria-hidden="true", so the button pulls its padding in and the link's name stays its words.
as"main" | "div"Render the region as a div when the site's Layout already wraps every page in its main, so the page keeps one main. Default "main".
actionsReactNodeMore ways out, after the home link: "Go to dashboard", "View demo".
gone{ href: string; label: string }A 410 is a page taken down on purpose: nothing went wrong, so it is no alert and offers no retry. gone names its one way out ("Read the blog", "/blog") in place of the home link.
hero(words: ErrorWords) => ReactNodeThe site's own title band in place of the message's heading (a site that keeps a client's brand lays its error page out as an interior page): it gets the words and draws the h1; the sentence and the ways out follow it in the page's column.

SignedOutPage

PropTypeRequiredDoes
appstringYesThe app's name: "Capsid Portal".
signInstringYesWhere signing in starts again: the app's own address.
byChoicebooleanYesThe person signed out here (true), or the session ended on its own (false).
accessbooleanUnder Access, an open Access session may sign the person straight back in: say so.
mainIdstring

CSS variables

VariableDefault
--error-page-body-gapvar(--gap)
--error-page-body-pad-block0
--error-page-hero-gapvar(--gap)

Parts and data attributes

ClassIs
.cap-error-pagethe root
.cap-error-page-bodya part
.cap-error-page-stacka part
AttributeValues
data-status404
StateRead from
:focusthe platform

Accessibility

KeyDoes
TabThe header's skip link first, then the header, then Try again (server errors) and Go to the home page
Enter on the skip linkMoves to main
  • The failed Empty's contract: shape, word and color together, role="alert", the title in --crit at 4.5:1 in both themes.
  • One h1, the title; one main. The header's skip link and landmarks come from the site's own header.
  • The development stack is a named, focusable region, so it scrolls by keyboard on a phone.