Skip to content

Commit

Permalink
fix: avoid postMessage warnings in console
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Pokorný <[email protected]>
  • Loading branch information
JanPokorny committed Jan 7, 2025
1 parent 1c9c8bd commit 86bc0a2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface AppState {
config: {
canFixError: boolean
},
ancestorOrigin: string,
}

// Page is loaded directly
Expand All @@ -26,12 +27,18 @@ const ALLOWED_ORIGINS = (import.meta.env.VITE_ALLOWED_FRAME_ANCESTORS ?? '').spl
},
theme: 'light',
fullscreen: false,
ancestorOrigin: ALLOWED_ORIGINS[0],
};

let app: any;

async function updateState(stateChange: Partial<AppState>) {
const oldState = { ...state };

// validate ancestorOrigin
if(!ALLOWED_ORIGINS.includes(stateChange.ancestorOrigin)) stateChange.ancestorOrigin = undefined;

// update state
state = { ...state, ...stateChange };

// set fullscreen
Expand Down Expand Up @@ -86,11 +93,11 @@ const ALLOWED_ORIGINS = (import.meta.env.VITE_ALLOWED_FRAME_ANCESTORS ?? '').spl
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
switch (data.type) {
case 'bee:ready':
ALLOWED_ORIGINS.forEach((origin: string) => parent.postMessage({ type: 'bee:ready' }, origin))
parent.postMessage({ type: 'bee:ready' }, state.ancestorOrigin);
return;

case 'bee:request':
ALLOWED_ORIGINS.forEach((origin: string) => parent.postMessage(data, origin));
parent.postMessage(data, state.ancestorOrigin);
return;

default:
Expand Down

0 comments on commit 86bc0a2

Please sign in to comment.