Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
# OpenSpec Change: enterprise-react-error-boundary
- **Change ID**: enterprise-react-error-boundary
- **Package**: `@suaveplan/react-error-boundary`
- **Category**: react
- **Target path**: `react/ui/react-error-boundary`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/react-error-boundary.md`
---
## Summary
Deliver `@suaveplan/react-error-boundary` on genesis from scratch at enterprise quality. A React class-component error boundary: `ErrorBoundary` (fallback/FallbackComponent/onError/onReset/resetKeys), `DefaultFallback`, and `useErrorBoundary` hook. Genesis adds `@suaveplan/error` integration, OTel span-event capture on catch, i18n for default fallback copy, Storybook stories, and Playwright E2E.
---
## Current-state audit (genesis)
Package does not exist on genesis — fresh build.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/error` (`workspace:^`) | `SuaveplanError` type narrowing in `onError` |
| `@suaveplan/react-translate` (`workspace:^`) | i18n for `DefaultFallback` copy |
| `@opentelemetry/api` (`catalog:observability`) | Span event `error_boundary.caught` |
External: `tslib catalog:build`. React 18 peer.
---
## Preserved public API surface
```ts
ErrorBoundary — getDerivedStateFromError + componentDidCatch, resetKeys, onError, onReset
DefaultFallback — minimal error UI with "Try again" button
useErrorBoundary — programmatic throw into nearest boundary
// Types
ErrorBoundaryProps, ErrorBoundaryState, FallbackProps, UseErrorBoundaryReturn
```
---
## New additions for genesis
1. **OTel `error_boundary.caught` span event** — attributes: `error.message`, `error.code` (if `SuaveplanError`), `error.type`.
2. **i18n `DefaultFallback`** — "Something went wrong", "Try again" via `useTranslation`.
3. **Storybook** — `ErrorBoundary` default (forced throw), `useErrorBoundary` playground, `DefaultFallback` standalone, custom `FallbackComponent`.
4. **Playwright E2E** — render a component that throws; verify fallback shown; click "Try again"; verify reset.
---
## File layout
```text
react/ui/react-error-boundary/
package.json
tsconfig.json
vitest.config.ts
src/
index.ts
components/
error-boundary/ (tsx + types + md + test + stories + index)
default-fallback/ (tsx + types + md + test + stories + index)
hooks/
use-error-boundary/ (ts + types + md + test + stories + index)
e2e/
error-boundary.spec.ts
```

View File

@@ -0,0 +1,80 @@
# Tasks: enterprise-react-error-boundary
**Change ID**: enterprise-react-error-boundary
**Package**: `@suaveplan/react-error-boundary`
**Target path**: `react/ui/react-error-boundary`
**Prerequisite packages on Verdaccio**: `@suaveplan/error`, `@suaveplan/react-translate`
---
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold
- [ ] Create directory tree per proposal layout.
- [ ] Write `package.json` at `0.1.0` with `"sideEffects": false`, exports map.
- [ ] Dependencies: `@suaveplan/error workspace:^`, `@suaveplan/react-translate workspace:^`, `@opentelemetry/api catalog:observability`, `tslib catalog:build`.
- [ ] Write `tsconfig.json`, `vitest.config.ts`, scripts.
---
## 2. Types
- [ ] Define `FallbackProps`: `{ error: Error; resetErrorBoundary: () => void }`.
- [ ] Define `ErrorBoundaryProps`: `children`, `fallback?: ReactNode`, `FallbackComponent?: ComponentType<FallbackProps>`, `onError?: (error, info) => void`, `onReset?: () => void`, `resetKeys?: unknown[]`.
- [ ] Define `ErrorBoundaryState`: `{ hasError: boolean; error: Error | null }`.
- [ ] Define `UseErrorBoundaryReturn`: `{ showBoundary: (error: Error) => void }`.
---
## 3. DefaultFallback
- [ ] Renders translated "Something went wrong" heading + error message (dev-only) + "Try again" button calling `resetErrorBoundary`.
- [ ] Uses `useTranslation` from `@suaveplan/react-translate`.
- [ ] Write `default-fallback.test.tsx`: renders heading, button calls reset. `{ timeout: 5000 }`.
- [ ] Write `default-fallback.stories.tsx`: default, with-error-message, playground.
- [ ] Write `default-fallback.md`.
---
## 4. ErrorBoundary
- [ ] Class component with `static getDerivedStateFromError(error)` and `componentDidCatch(error, info)`.
- [ ] `componentDidCatch` — calls `this.props.onError(error, info)`; emits OTel span event `error_boundary.caught` with attributes `error.message`, `error.type`, and `error.code` (if `error instanceof SuaveplanError`).
- [ ] `resetKeys` watching via `componentDidUpdate` — if any `resetKeys[i]` changed value, call `reset()`.
- [ ] Renders `FallbackComponent` if provided, else `fallback` prop, else `DefaultFallback`.
- [ ] Write `error-boundary.test.tsx`: catch + fallback rendered, reset clears error, onError called, onReset called, resetKeys trigger reset, FallbackComponent receives props. `{ timeout: 5000 }`.
- [ ] Write `error-boundary.stories.tsx`: default (forced throw), custom FallbackComponent, resetKeys, playground.
- [ ] Write `error-boundary.md` (≥200 words).
---
## 5. useErrorBoundary hook
- [ ] Uses `useState` to hold a thrown error; throws it in render via `useEffect` → nearest boundary catches it.
- [ ] Returns `{ showBoundary: (error: Error) => void }`.
- [ ] Write `use-error-boundary.test.tsx`: calling `showBoundary` causes boundary to catch. `{ timeout: 5000 }`.
- [ ] Write `use-error-boundary.stories.tsx`: playground (button calls `showBoundary`).
- [ ] Write `use-error-boundary.md`.
---
## 6. E2E
- [ ] `e2e/error-boundary.spec.ts` — Playwright:
- Render component that throws on click → `DefaultFallback` shown.
- Click "Try again" → component re-mounts without error.
- `FallbackComponent` renders with correct `error.message`.
---
## 7. Verify and publish
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/react-error-boundary` — green.
- [ ] `bunx turbo test:coverage --filter=@suaveplan/react-error-boundary` — 100%.
- [ ] `bun scripts/publish.ts --package @suaveplan/react-error-boundary`.
- [ ] Archive change folder.