@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
71 lines • 2.14 kB
TypeScript
/**
* Process @errorBoundary directives in templates.
*
* Syntax:
* @errorBoundary
* <content that might error>
* @fallback
* <fallback content shown on error>
* @enderrorBoundary
*
* Or with options:
* @errorBoundary(id: 'my-boundary', logErrors: false)
*/
export declare function processErrorBoundaryDirectives(template: string, context?: Record<string, unknown>, _filePath?: string): string;
/**
* Wrap content in a try/catch for SSR error handling.
* Returns the fallback if an error occurs during rendering.
*/
export declare function withErrorBoundary<T>(render: () => T | Promise<T>, fallback: T, onError?: (error: Error) => void): Promise<T>;
/**
* Create an error boundary wrapper function.
*/
export declare function createErrorBoundary<T>(fallback: T, options?: ErrorBoundaryOptions): (render: () => T | Promise<T>) => Promise<T>;
/**
* Generate CSS for error boundary styling.
*/
export declare function generateErrorBoundaryCSS(): string;
/**
* Generate client-side runtime for error boundaries.
*/
export declare function generateErrorBoundaryRuntime(): string;
/**
* STX Error Boundaries
*
* Provides graceful error handling for component trees.
* When an error occurs within an error boundary, the fallback content is shown
* instead of crashing the entire application.
*
* @module error-boundaries
*
* @example
* ```html
* @errorBoundary
* <RiskyComponent />
* @fallback
* <div class="error-state">
* <p>Something went wrong</p>
* <button @click="$retry()">Retry</button>
* </div>
* @enderrorBoundary
* ```
*/
// =============================================================================
// Types
// =============================================================================
export declare interface ErrorBoundaryOptions {
onError?: (error: Error, info: ErrorInfo) => void
logErrors?: boolean
id?: string
}
export declare interface ErrorInfo {
componentName?: string
stack?: string
timestamp: number
boundaryId: string
}
export declare interface ErrorBoundaryState {
hasError: boolean
error: Error | null
info: ErrorInfo | null
}