Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit a18ecfd

Browse files
committed
fix: improve actor state handling to prevent proxy issues (#1123)
Fixes FRONT-739
1 parent ed04f22 commit a18ecfd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/core/src/actor/instance.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ export class ActorInstance<
175175
},
176176
getState: async () => {
177177
this.#validateStateEnabled();
178-
return this.#persistRaw.s as unknown;
178+
179+
// Must return from `#persistRaw` in order to not return the `onchange` proxy
180+
return this.#persistRaw.s as Record<string, any> as unknown;
179181
},
180182
getRpcs: async () => {
181183
return Object.keys(this.#config.actions);
@@ -191,7 +193,13 @@ export class ActorInstance<
191193
},
192194
setState: async (state: unknown) => {
193195
this.#validateStateEnabled();
194-
this.#persistRaw.s = state as S;
196+
197+
// Must set on `#persist` instead of `#persistRaw` in order to ensure that the `Proxy` is correctly configured
198+
//
199+
// We have to use `...` so `on-change` recognizes the changes to `state` (i.e. set #persistChanged` to true). This is because:
200+
// 1. In `getState`, we returned the value from `persistRaw`, which does not have the Proxy to monitor state changes
201+
// 2. If we were to assign `state` to `#persist.s`, `on-change` would assume nothing changed since `state` is still === `#persist.s` since we returned a reference in `getState`
202+
this.#persist.s = { ...(state as S) };
195203
await this.saveState({ immediate: true });
196204
},
197205
};

0 commit comments

Comments
 (0)