Skip to content

Commit 7b53470

Browse files
committed
fix: catch iframe errors
1 parent 55fab14 commit 7b53470

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

apps/builder/app/shared/sync-client.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ export class ImmerhinSyncObject implements SyncObject {
6767
}
6868
setState(state: Map<string, unknown>) {
6969
for (const [namespace, $store] of this.store.containers) {
70-
// Immer cannot handle Map instances from another realm.
71-
// Use `clone` to recreate the data with the current realm's classes.
72-
// This works because the structured clone algorithm skips prototype chains; classes must be defined in both realms.
73-
$store.set(structuredClone(state.get(namespace)));
70+
// catch errors triggered by CSP configuration when user put iframe onto canvas
71+
try {
72+
// Immer cannot handle Map instances from another realm.
73+
// Use `clone` to recreate the data with the current realm's classes.
74+
// This works because the structured clone algorithm skips prototype chains; classes must be defined in both realms.
75+
$store.set(structuredClone(state.get(namespace)));
76+
} catch {
77+
// empty block
78+
}
7479
}
7580
}
7681
applyTransaction(transaction: Transaction<Change[]>) {
@@ -112,10 +117,15 @@ export class NanostoresSyncObject implements SyncObject {
112117
}
113118
applyTransaction(transaction: Transaction) {
114119
this.operation = "add";
115-
// `instanceof` checks do not work with instances like Map, File, etc., from another realm.
116-
// Use `clone` to recreate the data with the current realm's classes.
117-
// This works because the structured clone algorithm skips prototype chains; classes must be defined in both realms.
118-
this.store.set(structuredClone(transaction.payload));
120+
// catch errors triggered by CSP configuration when user put iframe onto canvas
121+
try {
122+
// `instanceof` checks do not work with instances like Map, File, etc., from another realm.
123+
// Use `clone` to recreate the data with the current realm's classes.
124+
// This works because the structured clone algorithm skips prototype chains; classes must be defined in both realms.
125+
this.store.set(structuredClone(transaction.payload));
126+
} catch {
127+
// empty block
128+
}
119129
this.operation = "local";
120130
}
121131
revertTransaction(_transaction: RevertedTransaction) {

0 commit comments

Comments
 (0)