Skip to content

v2.0.0

Latest

Choose a tag to compare

@jchiatt jchiatt released this 02 Dec 06:18
1487c36

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-chaos

What'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>, useChaos and ChaosProvider. 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 enabled is set on a ChaosProvider or an option. Chaos that is off is silent and touches no globals.
  • ChaosError carries seed, id and probability, so an error boundary can show or replay exactly what failed.
  • Packaging: CommonJS and ESM with types, behind an exports map. 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) becomes withChaos(C, { level, message, enabled }).
  • level now means exactly level / 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.

Full changes: #68, #71