From harness-claude
Implements XState shallow and deep history pseudo-states to remember and restore previous state configurations. Useful for pause/resume, modals, help screens, wizards, and undo-like navigation.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Remember and restore previous state configurations with shallow and deep history pseudo-states
Models concurrent, independent state regions active simultaneously in XState machines. Use for UIs with orthogonal concerns like bold/italic toggles or parallel processes like upload/validation.
Models complex UI flows as finite state machines with states, events, transitions, actions, and guards. Useful for forms, data fetching, authentication flows, and wizards.
Designs finite state machines and statecharts for modeling entity lifecycles, workflows, and system behaviors using Harel semantics, PlantUML, and Mermaid notation.
Share bugs, ideas, or general feedback.
Remember and restore previous state configurations with shallow and deep history pseudo-states
type: 'history'.history: 'shallow' (default) to remember only the immediate child state. Use history: 'deep' to remember the entire nested state configuration.target on the history state as a default — used when the compound state has never been entered before.// media-player.machine.ts
import { createMachine } from 'xstate';
const mediaPlayerMachine = createMachine({
id: 'player',
initial: 'stopped',
states: {
stopped: {
on: { PLAY: 'playing' },
},
playing: {
initial: 'normal',
states: {
normal: {
on: { FAST_FORWARD: 'fastForward', SLOW_MOTION: 'slowMotion' },
},
fastForward: {
on: { NORMAL: 'normal', SLOW_MOTION: 'slowMotion' },
},
slowMotion: {
on: { NORMAL: 'normal', FAST_FORWARD: 'fastForward' },
},
// History pseudo-state — remembers which playback mode was active
hist: {
type: 'history',
history: 'shallow',
target: 'normal', // Default if never entered before
},
},
on: {
PAUSE: 'paused',
STOP: 'stopped',
},
},
paused: {
on: {
// Resume returns to the exact playback mode (normal/ff/slow)
PLAY: 'playing.hist',
},
},
},
});
Shallow vs deep history:
shallow — remembers only the direct child state of the compound state. If that child has its own children, they start from their initial.deep — remembers the entire nested configuration, no matter how deep. Every level is restored.// Deep history example — multi-level wizard
states: {
wizard: {
initial: 'step1',
states: {
step1: {
initial: 'substepA',
states: {
substepA: { on: { NEXT: 'substepB' } },
substepB: { on: { NEXT: '#wizard.step2' } },
},
},
step2: { /* ... */ },
// Deep history restores step1.substepB if that's where we were
hist: { type: 'history', history: 'deep' },
},
on: { HELP: 'help' },
},
help: {
on: { BACK: 'wizard.hist' }, // Restores exact nested position
},
}
Default target: The target on a history state is used only when the compound state has never been entered. After the first entry, the history always resolves to the last known state.
Multiple history states: A compound state can have multiple history pseudo-states (e.g., one shallow and one deep), though this is uncommon.
History with parallel states: Deep history restores all parallel regions to their previous states. Shallow history restores only the top-level parallel configuration.
When NOT to use history: If the "return" always goes to a specific state, use a direct transition instead. History is for when the return destination depends on where the user was.
https://stately.ai/docs/history-states