Repository navigation
Expand file tree
/
Copy pathroot.tsx
More file actions
179 lines (169 loc) · 5.35 KB
/
Copy pathroot.tsx
File metadata and controls
179 lines (169 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { useEffect } from "react";
import {
isRouteErrorResponse,
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useRouteError,
} from "react-router";
import type { Route } from "./+types/root";
import { CookieNotice } from "./components/cookie-notice";
import { Logo } from "./components/logo";
import "./app.css";
/**
* Preload the two variable fonts.
*
* Both are render-blocking for the first meaningful paint, so fetching them in
* parallel with the CSS avoids a flash of fallback text and the layout shift
* that comes with it. `font-display: swap` covers the case where they are slow.
*/
export const links: Route.LinksFunction = () => [
{
rel: "preload",
href: "/fonts/jost-latin.woff2",
as: "font",
type: "font/woff2",
crossOrigin: "anonymous",
},
{
rel: "preload",
href: "/fonts/instrument-sans-latin.woff2",
as: "font",
type: "font/woff2",
crossOrigin: "anonymous",
},
{ rel: "icon", href: "/favicon.svg", type: "image/svg+xml" },
{ rel: "apple-touch-icon", href: "/icon-192.png" },
{ rel: "manifest", href: "/site.webmanifest" },
];
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#F1EDE3" />
{/*
iOS Safari turns anything that looks like an email address, a phone
number or a postal address into a tappable link of its own, styled
however it likes. The dashboard prints the signed-in address as plain
text, and Safari rendered it underlined and clickable — so it read as
a control, and tapping it opened Mail. Switching the detectors off is
the only way to keep text as text.
*/}
<meta name="format-detection" content="telephone=no,email=no,address=no" />
<Meta />
<Links />
</head>
<body>
{/* First thing in the tab order, so a keyboard user can jump the nav. */}
<a href="#main" className="skip-link">
Skip to content
</a>
{children}
{/* Site-wide, so the choice is asked once and applies everywhere. */}
<CookieNotice />
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export default function App() {
/**
* Marks the document as hydrated.
*
* Server-rendered inputs are in the DOM long before the JavaScript that owns
* them has run, so anything automating this app — the end-to-end suite, a
* synthetic monitor — needs a truthful "interactive now" signal rather than
* an arbitrary sleep. This effect fires on the hydration commit, which is
* exactly that moment.
*/
useEffect(() => {
document.documentElement.dataset.hydrated = "true";
}, []);
return <Outlet />;
}
/**
* The error boundary.
*
* Shows a stack trace ONLY in development. In production a visitor gets a plain
* apology and nothing about the internals — the detail is in the server log,
* findable by the request id.
*/
export function ErrorBoundary() {
const error = useRouteError();
const isDev = import.meta.env.DEV;
let title = "Something went wrong";
let message = "The page could not be loaded. Try again in a moment.";
let status = 500;
if (isRouteErrorResponse(error)) {
status = error.status;
if (error.status === 404) {
title = "Page not found";
message = "That page doesn't exist. It may have moved, or the link may be wrong.";
} else if (error.status === 401 || error.status === 403) {
title = "You don't have access to that";
message = "Sign in with an account that has permission, or head back to the homepage.";
} else {
title = "Something went wrong";
message = error.statusText || message;
}
}
return (
<main
id="main"
style={{
minHeight: "100dvh",
display: "grid",
placeItems: "center",
padding: "2rem 1.5rem",
}}
>
<div style={{ maxWidth: "34rem", width: "100%" }}>
<Logo size={22} />
<p
className="numeric"
style={{
marginTop: "3rem",
fontFamily: "var(--font-display)",
fontSize: "var(--text-h1)",
lineHeight: 1,
color: "var(--color-faint)",
}}
>
{status}
</p>
<h1 style={{ fontSize: "var(--text-h2)", marginTop: "0.75rem" }}>{title}</h1>
<p style={{ marginTop: "1rem", color: "var(--color-muted)", fontSize: "var(--text-lead)" }}>
{message}
</p>
<div style={{ display: "flex", gap: "0.75rem", marginTop: "2rem", flexWrap: "wrap" }}>
<a href="/" className="btn btn-ink">
Back to homepage
</a>
<a href="/contact" className="btn btn-quiet">
Contact support
</a>
</div>
{isDev && error instanceof Error && (
<pre
style={{
marginTop: "2.5rem",
padding: "1rem",
background: "var(--color-panel)",
border: "1px solid var(--color-rule)",
overflowX: "auto",
fontSize: "var(--text-fine)",
lineHeight: 1.5,
}}
>
{error.stack}
</pre>
)}
</div>
</main>
);
}