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
<script lang="ts">
import { ErrorBoundary } from '@inflector/keeno'
import Fragile from './Fragile.kn'
const caught = state(0)
</script>
<div class="demo">
<ErrorBoundary
fallback={(error, reset) => (
<div class="fallback" role="alert">
<span class="icon">!</span>
<div class="body">
<strong>Something broke</strong>
<code>{String(error)}</code>
</div>
<button onClick={reset}>Try again</button>
</div>
)}
onError={(error) => {
caught.set(caught.peek() + 1)
console.warn('Caught by the boundary:', error)
}}
>
<Fragile />
</ErrorBoundary>
<p class="meta">
<span>The child throws at 3; the boundary shows a fallback.</span>
<span class="count">caught {caught}</span>
</p>
</div>
<style>
.demo {
display: grid;
gap: 0.75rem;
}
.fallback {
display: flex;
align-items: center;
gap: 0.75rem;
min-height: 4.5rem;
padding: 0.875rem 1rem;
border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
border-radius: 0.75rem;
background: color-mix(in srgb, var(--danger) 6%, var(--bg));
}
.icon {
display: grid;
place-items: center;
flex: none;
width: 1.5rem;
height: 1.5rem;
border-radius: 50%;
background: color-mix(in srgb, var(--danger) 15%, transparent);
color: var(--danger);
font-size: 0.8rem;
font-weight: 700;
}
.body {
display: grid;
flex: 1;
min-width: 0;
}
strong {
font-weight: 500;
}
code {
overflow: hidden;
color: var(--muted);
font-size: 0.75rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.meta {
display: flex;
justify-content: space-between;
gap: 1rem;
margin: 0;
font-size: 0.75rem;
color: var(--muted);
}
.count {
flex: none;
font-family: var(--font-mono);
}
</style>