diff --git a/packages/core/src/getNextSnapshot.ts b/packages/core/src/getNextSnapshot.ts index 928de4b1b7..eda1071b94 100644 --- a/packages/core/src/getNextSnapshot.ts +++ b/packages/core/src/getNextSnapshot.ts @@ -22,7 +22,11 @@ export function createInertActorScope( stopChild: () => {}, system: self.system, spawnChild: (logic) => { - return createActor(logic) as any; + const child = createActor(logic) as any; + + child.start(); + + return child; } }; diff --git a/packages/core/test/actorLogic.test.ts b/packages/core/test/actorLogic.test.ts index afafd69006..e68b441122 100644 --- a/packages/core/test/actorLogic.test.ts +++ b/packages/core/test/actorLogic.test.ts @@ -338,12 +338,21 @@ describe('transition function logic (fromTransition)', () => { any, any, any - >((_state, _event, { spawnChild }) => { + >((state, _event, { spawnChild }) => { + if (state) { + return state; + } const childActor = spawnChild(fromPromise(() => Promise.resolve(42))); return childActor; }, undefined); - const actor = createActor(transitionLogic).start(); + const actor = createActor(transitionLogic); + actor.subscribe({ + error: (err) => { + console.error(err); + } + }); + actor.start(); actor.send({ type: 'anyEvent' }); expect(isActorRef(actor.getSnapshot().context)).toBeTruthy(); @@ -844,7 +853,7 @@ describe('machine logic', () => { id: 'child', src: createMachine({ context: ({ input }) => ({ - // this is only meant to showcase why we can't invoke this actor when it's missing in the persisted state + // this is meant to showcase why we can't invoke this actor when it's missing in the persisted state // because we don't have access to the right input as it depends on the event that was used to enter state `b` value: input.deep.prop })