Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"clear-source-names",
"codemod-migrate-cli",
"deferred-child-start",
"delayed-transition-context-patch",
"durable-logic-effects",
"eager-timeouts-delays",
"eleven-functions-inline",
Expand Down Expand Up @@ -104,6 +105,7 @@
"persist-state-input",
"plain-targets",
"portable-code-serialization",
"proud-states-schemas",
"proud-timers-migrate",
"provide-actor-variance",
"public-effect-introspection",
Expand Down Expand Up @@ -131,6 +133,7 @@
"store-is-atom",
"swift-invoke-stops",
"swift-send-typing",
"tidy-transition-arrays",
"timeout-receives-input",
"type-only-schemas",
"typed-invoke-targets",
Expand Down
68 changes: 68 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,73 @@
# xstate

## 6.0.0-alpha.26

### Patch Changes

- d46fbd2: Delayed transitions (`onTimeout` and `after`) and error transitions (`onError`) in machines created with `setup({ states })` now type the `context` patch against the **target** state's context schema, matching the behavior of `on:` transitions. Previously, a cross-state context patch that was valid at runtime failed to typecheck:

```ts
const machine = setup({
schemas: {
context: z.object({ reason: z.union([z.literal('timeout'), z.null()]) })
},
states: {
running: { schemas: { context: z.object({ reason: z.null() }) } },
expired: {
schemas: { context: z.object({ reason: z.literal('timeout') }) }
}
}
}).createMachine({
context: { reason: null },
initial: 'running',
states: {
running: {
timeout: 5000,
// Previously a type error; now checked against `expired`'s context
onTimeout: () => ({
target: 'expired',
context: { reason: 'timeout' as const }
})
},
expired: { type: 'final' }
}
});
```

- d9d9e29: Per-state schemas declared in `setup({ states })` are now available on the compiled machine's state nodes via `machine.states.X.schemas`, so tooling (e.g. per-state snapshot validators) can be derived from the machine alone. Previously they were only accessible on the setup return value.

```ts
import { setup, types } from 'xstate';

const machine = setup({
states: {
running: {
schemas: { context: types<{ startedAt: number }>() }
}
}
}).createMachine({
initial: 'running',
states: {
running: {}
}
});

machine.states.running.schemas?.context; // the schema declared in setup
```

- 7da1486: Transition arrays are no longer accepted by the v6 `createMachine(...)` authoring API. Use a transition function to select among targets:

```ts
createMachine({
always: ({ context }) => {
if (context.hour < 12) return { target: 'morning' };
return { target: 'afternoon' };
}
});
```

Serialized transition arrays remain supported by `createMachineFromConfig(...)`.

## 6.0.0-alpha.25

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xstate",
"version": "6.0.0-alpha.25",
"version": "6.0.0-alpha.26",
"description": "Finite State Machines and Statecharts for the Modern Web.",
"main": "dist/xstate.cjs.js",
"bin": {
Expand Down