From 3365779ce3ac463b5837ea3086e9477ab796880b Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 14 Jun 2025 15:46:17 +0300 Subject: [PATCH 1/2] fix: catch iframe errors --- apps/builder/app/shared/sync-client.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/builder/app/shared/sync-client.ts b/apps/builder/app/shared/sync-client.ts index 8b730b846f3e..6d1e9d0d82a5 100644 --- a/apps/builder/app/shared/sync-client.ts +++ b/apps/builder/app/shared/sync-client.ts @@ -67,10 +67,15 @@ export class ImmerhinSyncObject implements SyncObject { } setState(state: Map) { for (const [namespace, $store] of this.store.containers) { - // 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))); + // catch errors triggered by CSP configuration when user put iframe onto canvas + try { + // 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))); + } catch { + // empty block + } } } applyTransaction(transaction: Transaction) { @@ -112,10 +117,15 @@ export class NanostoresSyncObject implements SyncObject { } applyTransaction(transaction: Transaction) { this.operation = "add"; - // `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)); + // catch errors triggered by CSP configuration when user put iframe onto canvas + try { + // `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)); + } catch { + // empty block + } this.operation = "local"; } revertTransaction(_transaction: RevertedTransaction) { From c282c212d1e13a1f9b42dba34b1161d1fdede58b Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 14 Jun 2025 15:53:59 +0300 Subject: [PATCH 2/2] Log error --- apps/builder/app/shared/sync-client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/builder/app/shared/sync-client.ts b/apps/builder/app/shared/sync-client.ts index 6d1e9d0d82a5..e646ad6bac34 100644 --- a/apps/builder/app/shared/sync-client.ts +++ b/apps/builder/app/shared/sync-client.ts @@ -73,8 +73,8 @@ export class ImmerhinSyncObject implements SyncObject { // 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))); - } catch { - // empty block + } catch (error) { + console.error(error); } } } @@ -123,8 +123,8 @@ export class NanostoresSyncObject implements SyncObject { // 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)); - } catch { - // empty block + } catch (error) { + console.error(error); } this.operation = "local"; }