fix(ui): only populate settings on main page

before, the init script was executed for every loaded iframe and was resetting `localStorage` everytime. It didn't show because the UI had its own copy of the settings via useState() - but now that it's reading directly from local storage, it shows.

The fix is to ensure that the script isn't executed in iframes.
This commit is contained in:
Simon Knott 2024-08-01 15:55:14 +02:00
parent a83134b270
commit e344c59630
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -90,6 +90,8 @@ export async function syncLocalStorageWithSettings(page: Page, appName: string)
// iframes w/ snapshots, etc.
if (location && location.protocol === 'data:')
return;
if (window.top !== window)
return;
Object.entries(settings).map(([k, v]) => localStorage[k] = v);
(window as any).saveSettings = () => {
(window as any)._saveSerializedSettings(JSON.stringify({ ...localStorage }));