Method ErrorBoundary
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
ErrorBoundary(Func<Exception, VNode>, VNode?[], string?)
Helper that wraps children in an inline Error Boundary with the given fallback.
Catches exceptions thrown during render of the child tree (including rethrows from pending Suspense
resources via Hooks.Use) and renders the VNode produced by fallback instead.
Useful for reducing boilerplate where introducing a dedicated [Component(IsErrorBoundary = true)]
wrapper class would be overkill (e.g. a root boundary directly under Mount).
public static ComponentNode ErrorBoundary(Func<Exception, VNode> fallback, VNode?[] children, string? key = null)
Parameters
fallbackFunc<Exception, VNode>Factory that receives the caught exception and returns the fallback VNode.
childrenVNode[]Child nodes rendered in the normal (non-error) path.
keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode wrapping
childrenin an Error Boundary.
Remarks
When placing multiple V.ErrorBoundary instances at the same position, always supply
key to avoid identity collisions in the reconciler. The helper's lambda body
has the same MethodInfo on every call, so siblings cannot be distinguished without a key.
fallback and children are captured into the closure on the
initial mount; the same fiber is reused on parent re-renders so subsequent value changes are
not reflected. For dynamic cases, read values via Context / Hooks, or use the function-style
pattern with [Component(IsErrorBoundary = true)] + Hooks.UseFallback.
Each invocation allocates a closure (DisplayClass + delegate). The helper is intended for
root boundaries directly under Mount; calling it repeatedly inside a render function will
allocate on every render.