@gluebi/vue-resilient-error-boundary
v1.0.0
Published
Vue 3 error boundary that freezes DOM on error instead of unmounting content
Maintainers
Readme
@gluebi/vue-resilient-error-boundary
Vue 3 error boundary that freezes DOM on error instead of unmounting content.
When a child component throws, this component:
- Snapshots the current DOM (taken on mount and refreshed on error)
- Replaces the live component tree with frozen HTML via
v-html - Blocks interaction with a
pointer-events: noneoverlay andcursor: not-allowed - Emits an
@errorevent for the consumer to handle logging
No existing Vue/Nuxt library does this — every error boundary unmounts content and shows a fallback. This component preserves what the user was seeing.
Install
pnpm add @gluebi/vue-resilient-error-boundaryUsage (Vue 3)
<script setup>
import { ResilientErrorBoundary } from '@gluebi/vue-resilient-error-boundary'
import '@gluebi/vue-resilient-error-boundary/style.css'
</script>
<template>
<ResilientErrorBoundary context="product-tile-42" @error="handleError">
<ProductTile :product="product" />
</ResilientErrorBoundary>
</template>Usage (Nuxt 3)
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@gluebi/vue-resilient-error-boundary/nuxt'],
})The Nuxt module auto-imports the component and CSS. No manual imports needed:
<template>
<ResilientErrorBoundary context="product-tile-42" @error="handleError">
<ProductTile :product="product" />
</ResilientErrorBoundary>
</template>Enriched logging with provide/inject
For parent-level error handlers with enriched context (e.g., container data for Datadog):
import { RESILIENT_ERROR_HANDLER_KEY } from '@gluebi/vue-resilient-error-boundary'
// In a parent/wrapper component:
provide(RESILIENT_ERROR_HANDLER_KEY, (error: Error, context: string) => {
logger.error('tile-error', { error, context, containerData })
})The handler receives the normalized Error object and the context string from the boundary.
Props
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| context | string | 'unknown' | Identifier passed to @error and the injected handler |
Events
| Event | Payload | Description |
|-------|---------|-------------|
| error | Error | Emitted when a child component throws |
How it works
- Uses
display: contentson wrapper elements — invisible to CSS grid/flexbox - Snapshots
innerHTMLon mount and refreshes inonErrorCaptured(before state change) - Uses Vue's
onErrorCaptureddirectly (not wrappingNuxtErrorBoundary) - Returns
falsefromonErrorCapturedto stop error propagation - Frozen content has
pointer-events: nonewith a::afteroverlay usingpointer-events: autoandcursor: not-allowed
Requirements
- Vue 3.5+
- Nuxt 3+ (optional, for module usage)
