diff --git a/.changeset/soft-rats-battle.md b/.changeset/soft-rats-battle.md new file mode 100644 index 0000000000..f11728d10f --- /dev/null +++ b/.changeset/soft-rats-battle.md @@ -0,0 +1,7 @@ +--- +'xstate': patch +--- + +The `.provide(…)` method will now work as expected when implementing higher-level logic for machines. + +See https://github.com/statelyai/xstate/issues/4868 for the original issue. diff --git a/packages/core/src/StateMachine.ts b/packages/core/src/StateMachine.ts index d204aff983..8e3ad26958 100644 --- a/packages/core/src/StateMachine.ts +++ b/packages/core/src/StateMachine.ts @@ -152,6 +152,7 @@ export class StateMachine< this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this); this.restoreSnapshot = this.restoreSnapshot.bind(this); this.start = this.start.bind(this); + this.provide = this.provide.bind(this); this.root = new StateNode(config, { _key: this.id, diff --git a/packages/core/test/actorLogic.test.ts b/packages/core/test/actorLogic.test.ts index 9cba36d698..4d528886ef 100644 --- a/packages/core/test/actorLogic.test.ts +++ b/packages/core/test/actorLogic.test.ts @@ -1031,4 +1031,13 @@ describe('composable actor logic', () => { }) ); }); + + it('higher-level machine logic should work with persist()', () => { + const machine = createMachine({}); + const customLogic = { + ...machine + }; + + expect(customLogic.provide).toBeDefined(); + }); });