Skip to content

[Feature] Introduce widgets.ErrorBoundary for Component-Level Crash Isolation #11

@HaHiepThanh

Description

@HaHiepThanh

📋 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:

  1. widgets.ErrorBoundary Definition:
    Create a new wrapper widget:
    type ErrorBoundary struct {
        Fallback func(err error) gutter.Widget
        Child    gutter.Widget
    }
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions