Skip to content

Commit 59fafb5

Browse files
committed
fix: dont send unserializable snapshots
Signed-off-by: aabidsofi19 <[email protected]>
1 parent c40bb2c commit 59fafb5

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/actors/validators/dataValidator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,14 @@ export const dataValidatorMachine = setup({
168168
waiting: {},
169169
debouncing: {
170170
after: {
171-
debounceTimeout: '#validationMachine.validatingData'
171+
debounceTimeout: '#validatingData'
172172
}
173173
}
174174
}
175175
},
176176

177177
validatingData: {
178+
id: 'validatingData',
178179
invoke: {
179180
src: 'ValidateActor',
180181
input: ({ context }: { context: ValidationMachineContext }) => ({

src/actors/worker/fromWorkerfiedActor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const fromWorkerfiedActor = (
8181
};
8282
}
8383
if (event.type == WORKER_EVENTS.STATE_SNAPSHOT) {
84-
const snapshot = (event as STATE_SNAPSHOT_EVENT).data.snapshot;
84+
const snapshot = (event as STATE_SNAPSHOT_EVENT).data.snapshot as AnyMachineSnapshot;
8585
return {
8686
...state,
8787
...(snapshot || {})
@@ -110,7 +110,7 @@ export const fromWorkerfiedActor = (
110110
context: {},
111111
matches: function (value: StateValue) {
112112
const currentValue = (this as WorkerSnapshot).value;
113-
return matchesState(currentValue, value);
113+
return matchesState(value, currentValue);
114114
}
115115
} as unknown as AnyMachineSnapshot;
116116
},

src/actors/worker/workerfy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ const ProxyActor = setup({
3737

3838
const syncSnapshot = (actorRef: AnyActorRef) => {
3939
return actorRef.subscribe((snapshot) => {
40-
postMessage(workerEvents.stateSnapshot(snapshot.toJSON()));
40+
const jsonSnapshot = snapshot.toJSON();
41+
delete jsonSnapshot.children; // children are not serializable
42+
try {
43+
postMessage(workerEvents.stateSnapshot(jsonSnapshot));
44+
} catch (error) {
45+
console.error('Error sending snapshot from worker', error, jsonSnapshot);
46+
}
4147
});
4248
};
4349

0 commit comments

Comments
 (0)