📋 Context & Problem Description
In WebAssembly Go runtimes, if a widget panics during its Build() cycle, lifecycle callbacks, or event execution (due to a nil pointer dereference, slice index out of bounds, etc.), the entire WASM main-thread panic crashes. This freezes the client-side execution, forcing the user to reload the page to make the site responsive again.
💡 Proposed Solution & Implementation Plan
Introduce a component-level error boundary widget to contain panics:
widgets.ErrorBoundary Definition:
Create a new wrapper widget:
type ErrorBoundary struct {
Fallback func(err error) gutter.Widget
Child gutter.Widget
}
- Panic Recovery in Reconciler:
- Inside the element tree reconciliation and build cycles (
element_wasm.go), wrap the Build() and reconcile invocations with a defer recover() check.
- If a panic is caught:
- Halt rendering for the affected subtree.
- Propagate the error up to the nearest
ErrorBoundary element.
- Render the fallback widget returned by
Fallback(err) in place of the crashed component, preserving the rest of the application tree.
🎯 Impact & Benefits
- App Stability: Prevent a minor crash in a non-critical sidebar widget from crashing the entire SPA dashboard.
- Graceful Degradation: Display clean error states and retry buttons rather than a blank frozen screen.
🏷️ Suggested Labels
feature, wasm, widgets
📋 Context & Problem Description
In WebAssembly Go runtimes, if a widget panics during its
Build()cycle, lifecycle callbacks, or event execution (due to a nil pointer dereference, slice index out of bounds, etc.), the entire WASM main-thread panic crashes. This freezes the client-side execution, forcing the user to reload the page to make the site responsive again.💡 Proposed Solution & Implementation Plan
Introduce a component-level error boundary widget to contain panics:
widgets.ErrorBoundaryDefinition:Create a new wrapper widget:
element_wasm.go), wrap theBuild()andreconcileinvocations with adefer recover()check.ErrorBoundaryelement.Fallback(err)in place of the crashed component, preserving the rest of the application tree.🎯 Impact & Benefits
🏷️ Suggested Labels
feature,wasm,widgets