@implements IDisposable
@* Confines an exception thrown while rendering or handling an event on a page to the page body, instead
of killing the whole Blazor circuit (the blank "reload" bar).
WHERE IT MAY LIVE: this host's is static SSR, so MainLayout renders statically and every
@rendermode InteractiveServer page is its OWN interactive root, not a child of anything in the layout.
A boundary in the layout therefore never sees a page failure and its Recover/navigation handlers are
dead. The boundary has to sit INSIDE the interactive root — i.e. each interactive page wraps its body
in . Pinned by AdminUiFormSweepGuardTests (every interactive page wraps) and
PageErrorBoundaryTests (the component really contains a throw and recovers).
It does NOT catch exceptions from async-void handlers or timer callbacks. *@
@ChildContent
This page hit an unexpected error.
@ex.GetType().Name: @ex.Message
@code {
private ErrorBoundary? _boundary;
[Parameter] public RenderFragment? ChildContent { get; set; }
[Inject] private NavigationManager Nav { get; set; } = default!;
protected override void OnInitialized() => Nav.LocationChanged += OnLocationChanged;
/// Clears a tripped boundary and re-renders the wrapped content.
public void Recover() => _boundary?.Recover();
// A fresh navigation (e.g. same page, new route parameters, where the component instance is reused)
// clears a tripped boundary so the new location isn't stuck behind the old error. InvokeAsync keeps
// the Recover on the renderer's dispatcher.
private void OnLocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e)
=> _ = InvokeAsync(Recover);
///
public void Dispose() => Nav.LocationChanged -= OnLocationChanged;
}