Repository navigation
The 2019 proof of concept, rebuilt. Chaos is now seeded and replayable, off until you turn it on, and works with React 18 and 19.
npm install react-chaosWhat's new
- Seeded, deterministic failures.
shouldFail({ seed, id, probability })hashes the seed and id, so the same seed fails the same components every time. Share a link with?chaos=<seed>and anyone sees the same failures (readChaosSeedFromLocation()). - A small React API:
withChaos,<Chaos>,useChaosandChaosProvider. One provider can switch chaos on for a whole tree and set its seed and probability. - Off by default, in development and production alike, until
enabledis set on aChaosProvideror an option. Chaos that is off is silent and touches no globals. ChaosErrorcarriesseed,idandprobability, so an error boundary can show or replay exactly what failed.- Packaging: CommonJS and ESM with types, behind an
exportsmap. Both formats share one implementation, so a provider in an ESM app reaches components in a CJS library.'use client'is set for the Next.js App Router.sideEffects: false. - A new demo on Vite and React 19.
Breaking changes
2.0 replaces the 2019 API (0.1.0 and 1.0.2–1.0.6). The 0.1 package could not be installed at all (#10), so few apps should need to migrate.
- Named exports only:
import { withChaos } from 'react-chaos'. withChaos(C, level, message, runInProduction)becomeswithChaos(C, { level, message, enabled }).levelnow means exactlylevel / 10, so level 10 is 100%. The default probability is 0.5.- Peer dependency: React
^18 || ^19. React 16 and 17 are no longer supported.
See Migrating from 0.1 or 1.0 in the README.
Credits
Inspired by Brandon Dail's Fault Tolerance in React.
What's next
The roadmap is in #67: Playwright replay, a Storybook disaster gallery, hydration and Suspense faults, a DevTools panel and more.