diff --git a/apps/builder/app/shared/sync-client.ts b/apps/builder/app/shared/sync-client.ts index 3abc3199783..ee7a7846126 100644 --- a/apps/builder/app/shared/sync-client.ts +++ b/apps/builder/app/shared/sync-client.ts @@ -42,8 +42,9 @@ export class ImmerhinSyncObject implements SyncObject { } setState(state: Map) { for (const [namespace, $store] of this.store.containers) { - // immer is not able to work with Map instances from another realm - // use clone to recreate data with current realm classes + // Immer cannot handle Map instances from another realm. + // Use `clone` to recreate the data with the current realm's classes. + // This works because the structured clone algorithm skips prototype chains; classes must be defined in both realms. $store.set(structuredClone(state.get(namespace))); } } @@ -86,7 +87,10 @@ export class NanostoresSyncObject implements SyncObject { } addTransaction(transaction: Transaction) { this.operation = "add"; - this.store.set(transaction.payload); + // `instanceof` checks do not work with instances like Map, File, etc., from another realm. + // Use `clone` to recreate the data with the current realm's classes. + // This works because the structured clone algorithm skips prototype chains; classes must be defined in both realms. + this.store.set(structuredClone(transaction.payload)); this.operation = "local"; } revertTransaction(_transaction: RevertedTransaction) {