Skip to content

Commit 0face2a

Browse files
Merge pull request #25 from systemfsoftware/xs/upstream-subtree
build(repo): vendor upstream statelyai/xstate at 2146ae26 as a read-only subtree
2 parents 9f01956 + c75ddcd commit 0face2a

2,041 files changed

Lines changed: 302729 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
- leg: test
3232
runs-on: ubuntu-latest
3333
gate: pnpm test
34+
# full history: the git-subtree-split trailer that pins repos/xstate-upstream must be reachable
35+
fetch-depth: "0"
3436
- leg: dist
3537
runs-on: ubuntu-latest
3638
gate: pnpm gate:dist
@@ -42,6 +44,7 @@ jobs:
4244
steps:
4345
- uses: actions/checkout@v7
4446
with:
47+
fetch-depth: ${{ matrix.fetch-depth || '1' }}
4548
persist-credentials: false
4649
- uses: ./.github/actions/dev-shell
4750
- name: Turbo cache

‎commitlint.config.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ const stagedFiles = (): readonly string[] =>
9292
.map((l: string) => l.trim())
9393
.filter((l: string) => l.length > 0)
9494

95+
const SUBTREE_TRAILERS = [/^git-subtree-dir: \S+$/m, /^git-subtree-split: [0-9a-f]{40}$/m] as const
96+
const isSubtreeSquash = (commit: string) => SUBTREE_TRAILERS.every((trailer) => trailer.test(commit))
97+
const isSubtreeAdd = (commit: string) => /^Merge commit '[0-9a-f]{40}' as '[^']+'\s*$/.test(commit)
98+
9599
const configuration: UserConfig = {
96100
extends: ['@commitlint/config-conventional'],
97101

@@ -224,7 +228,7 @@ const configuration: UserConfig = {
224228
},
225229

226230
defaultIgnores: true,
227-
ignores: [(commit) => commit.startsWith("Squashed '") || commit.includes('git-subtree-dir:')],
231+
ignores: [isSubtreeSquash, isSubtreeAdd],
228232
formatter: '@commitlint/format',
229233
}
230234

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"test:sandbox": "nix run .#sandbox-proofs && deno test --config=scripts/deno.json --allow-run=git,sandbox,sh --allow-env --allow-read --allow-write sandbox-proofs/",
4242
"typecheck": "sandbox -- turbo --concurrency=${TURBO_CONCURRENCY:-50%} --continue typecheck typecheck:node",
4343
"typecheck:node": "tsc -p tsconfig.node.json --noEmit",
44-
"test:scripts": "deno test --config=scripts/deno.json --allow-read --allow-write --allow-run=awk --allow-import=jsr.io --allow-env scripts/"
44+
"test:scripts": "deno test --config=scripts/deno.json --allow-read --allow-write --allow-run=awk,git --allow-import=jsr.io --allow-env scripts/"
4545
},
4646
"type": "module"
4747
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@4.0.0/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"format": false,
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"ignore": ["@xstate/example-*", "store-*", "local-store-*"],
10+
"snapshot": {
11+
"useCalculatedVersion": true
12+
},
13+
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
14+
"onlyUpdatePeerDependentsWhenOutOfRange": true
15+
}
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mode": "pre",
3+
"tag": "alpha"
4+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'xstate': minor
3+
---
4+
5+
Actors now have deterministic, location-transparent identity.
6+
7+
- Every actor has a logical `address`: the `/`-joined path of actor ids from the root. Root actors are named after their logic's `id`, and children spawned without an explicit id get deterministic per-parent counters keyed by their actor source (`worker:0`, `worker:1`). Addresses are stable across persistence and restore; `sessionId` identifies one incarnation of an address, and completions from a previous incarnation of a local child are dropped.
8+
- `enq.spawn(actors.x)` records the registered source key so spawned children persist by key.
9+
- `getEffectDescriptor(effect)` returns a serializable view of any executable effect, with actor references replaced by addresses and actor sources by source keys (payload fields pass through by reference).
10+
- A host runtime can be installed as `system.runtime`; the built-in local runtime is the default. The new `deliverEvent`, `stopActor` and `terminateActor` helpers expose the local behaviors for custom runtimes to delegate to.
11+
- `createDurable` (from `xstate/durable`) adapters carry their runtime operations directly (`sendEvent`, `scheduleTimer`, …), and the execution installs them on every snapshot's actor system; it exposes `rootAddress` and `getActorRef(snapshot)`, tags every effect with a serializable `descriptor`, and `executeEffects` resolves only when every transitively initiated runtime operation has been accepted — returning the events addressed to the root actor for the durable loop. Breaking for existing adapters: during `executeEffects`, root-addressed events no longer reach any runtime `sendEvent` (including per-effect `runtime()` implementations) — drain them from the `executeEffects` result instead. While the loop is parked in `waitForEvent`, a root-addressed event reaches `sendEvent` like any other target, and the host should enqueue it in its own mailbox. Runtime objects are also wrapped before effects see them, so identity comparisons and extra non-runtime properties on the returned object are not preserved.
12+
- `getPersistedSnapshot(snapshot, { embedChildren: false })` persists children by logical address, leaving each child's state with the runtime that owns it; restoring an address-only child produces a location-transparent handle whose sends route through the system runtime.
13+
- Explicit child ids are unique per parent: spawning or invoking with an id already held by a live sibling throws (ids stopped earlier in the same transition stay reusable). Previously a duplicate id silently created a second running actor at the same address. A transition to a history state that restores its own source now exits and reenters the source, so its invoked actors restart instead of leaking.
14+
- Undeliverable events are reported through the new `deadLetter` runtime operation and a `@xstate.deadletter` inspection event. Delivery stays at-most-once — this is observability, not retry.
15+
- A persisted remote child entry round-trips an optional opaque `incarnation` token. XState never stamps one, but when a host does, completions from a different incarnation of the address are dropped and `sendTo` effect descriptors journal the target's token.
16+
- `createDurable` exposes `machineId` and `machineVersion` so hosts can pin an execution's journal to the machine version that produced it.
17+
- Async-actor steps (`enq.step`) route through the new `runStep` runtime operation. The built-in behavior memoizes results in the actor's own snapshot as before; a durable host implements `runStep` to own the step journal, replaying memoized results without re-running the step. The `runStep` helper export exposes the built-in behavior.
18+
- Serialized actor references (`Actor.toJSON`, persisted context refs) carry `xstate$type: 'actorRef'` instead of the v5 `xstate$$type: 1` marker. Migrate v5-persisted context refs with `machineVersions` if you restore them.
19+
- Timers persisted from a running actor carry their wall-clock start (`startedAt`); restoring the snapshot schedules the remaining time toward the original deadline (clamped to the declared delay), so a timer past due fires immediately instead of restarting its full delay. Pure-transition snapshots carry no timestamp and restart the declared delay.
20+
21+
```ts
22+
const durable = createDurable(machine, {
23+
sendEvent: (source, target, event) =>
24+
host.send(source?.address, target.address, event),
25+
executeAction: (action, { id }, runtime) =>
26+
host.runAction(id, () => action.exec(runtime)),
27+
waitForEvent: ({ id }) => host.waitForEvent(id)
28+
});
29+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'xstate': minor
3+
---
4+
5+
Route rejected promises returned from custom actions to the actor's error handling, so a state's `onError` catches a failed async action instead of leaving an unhandled rejection. A rejection that was previously ignored now errors the actor when no `onError` handles it.
6+
7+
```ts
8+
const machine = createMachine({
9+
initial: 'active',
10+
states: {
11+
active: {
12+
on: {
13+
SAVE: (_, enq) => {
14+
enq(() => saveToServer()); // returns a Promise
15+
}
16+
},
17+
onError: { target: 'failed' }
18+
},
19+
failed: {}
20+
}
21+
});
22+
```
23+
24+
Add the `ErrorFrom` type helper. `invoke.onError` events are typed from the invoked actor's error type when the actor logic declares one.
25+
26+
Add an optional `passive` flag to `Observer`. A passive observer only tracks the actor's lifecycle and does not count as an error handler, so an unhandled actor error is still reported when every observer with an `error` callback is passive.
27+
28+
An unhandled actor error is now reported one macrotask later than before, and a subscriber with an `error` callback that attaches in that window takes the error instead. Tests that advance fake timers by a single tick to observe the report need one more tick.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
"xstate": minor
3+
---
4+
5+
`createAsyncLogic` accepts `schemas.error`. It types the actor's `error` snapshot field and `event.error` in the invoking machine's `onError`. Without it, the error stays `unknown`, so reading properties from it is a type error.
6+
7+
```ts
8+
const fetchUser = createAsyncLogic({
9+
schemas: {
10+
output: z.object({ name: z.string() }),
11+
error: z.object({ code: z.string() }),
12+
},
13+
run: async () => ({ name: "David" }),
14+
});
15+
16+
setup({ actors: { fetchUser } }).createMachine({
17+
invoke: {
18+
src: "fetchUser",
19+
onError: ({ event }) => {
20+
event.error.code; // string
21+
},
22+
},
23+
});
24+
```
25+
26+
Without `schemas.error`, narrow `event.error` before reading from it.
27+
28+
With a `timeout`, the error type also includes `TimeoutError`, so narrow before reading schema fields:
29+
30+
```ts
31+
onError: ({ event }) => {
32+
if (event.error instanceof TimeoutError) return;
33+
event.error.code; // string
34+
};
35+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"xstate": patch
3+
"@xstate/react": patch
4+
---
5+
6+
Stop child actors and their timers and subscriptions when an unhandled parent error occurs, including when a stop action has not executed yet.
7+
8+
Keep `useActorRef` observers subscribed when the actor is replaced, and subscribe before the replacement starts.

0 commit comments

Comments
 (0)