ErrorBoundary wraps a child view and catches panics during rendering. Accepts either a View, a Viewable, or a *componentNode. Viewable values are wrapped into a component so their Body() call is guarded. The fallback is registered on the component as a side channel; the rendering path consults it o
(child any, fallback func(err error) View)
| 12 | // component across re-renders only updates the fallback, instead of |
| 13 | // nesting panic-recovery wrappers around renderFn. |
| 14 | func ErrorBoundary(child any, fallback func(err error) View) *viewNode { |
| 15 | view := asView(child) |
| 16 | if view == nil { |
| 17 | return &viewNode{kind: viewKindGroup} |
| 18 | } |
| 19 | if comp, ok := view.(*componentNode); ok { |
| 20 | comp.errFallback = fallback |
| 21 | return comp.viewNode() |
| 22 | } |
| 23 | return view.viewNode() |
| 24 | } |
| 25 | |
| 26 | func toError(r any) error { |
| 27 | switch v := r.(type) { |