Skip to content

Commit

Permalink
Fixed an issue with persisting children that got rehydrated (#4425)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Nov 3, 2023
1 parent 36cb3ae commit 74baddc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-cheetahs-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Fixed an issue with persisting children that got rehydrated.
1 change: 1 addition & 0 deletions packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export class StateMachine<
id: actorId,
parent: _actorScope?.self,
state: actorState,
src,
systemId: actorData.systemId
});

Expand Down
26 changes: 26 additions & 0 deletions packages/core/test/rehydration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,30 @@ describe('rehydration', () => {

expect(spy).not.toHaveBeenCalled();
});

it('should be possible to persist a rehydrated actor that got its children rehydrated', () => {
const machine = createMachine(
{
invoke: {
src: 'foo'
}
},
{
actors: {
foo: fromPromise(() => Promise.resolve(42))
}
}
);

const actor = createActor(machine).start();

const rehydratedActor = createActor(machine, {
state: actor.getPersistedState()
}).start();

const persistedChildren = (rehydratedActor.getPersistedState() as any)
.children;
expect(Object.keys(persistedChildren).length).toBe(1);
expect((Object.values(persistedChildren)[0] as any).src).toBe('foo');
});
});

0 comments on commit 74baddc

Please sign in to comment.