diff --git a/src/editor/scene-settings/scene-settings.ts b/src/editor/scene-settings/scene-settings.ts index bf513a7b7..93e1a0da4 100644 --- a/src/editor/scene-settings/scene-settings.ts +++ b/src/editor/scene-settings/scene-settings.ts @@ -46,6 +46,7 @@ editor.once('load', () => { let entitiesLoaded = false; let projectUserSettingsLoaded = false; let migrateEntityHandle = null; + let reloading = false; const migrateCameraSettings = () => { if (!entitiesLoaded || !projectUserSettingsLoaded) { return; @@ -97,10 +98,16 @@ editor.once('load', () => { migrateEntityHandle = editor.on('entities:add', migrateEntity); editor.call('status:clear'); - if (editor.call('permissions:write')) { + if (editor.call('permissions:write') && !reloading) { + reloading = true; + + // reloading before the server has the changes loses them, and the next load migrates again setTimeout(() => { - editor.call('settings:project').set('engineV2', true); - window.location.reload(); + const projectSettings = editor.call('settings:project'); + projectSettings.set('engineV2', true); + projectSettings.whenNothingPending(() => { + editor.api.globals.realtime.scenes.current.whenNothingPending(() => window.location.reload()); + }); }); } }; diff --git a/src/editor/settings/settings.ts b/src/editor/settings/settings.ts index 4807080c0..517564060 100644 --- a/src/editor/settings/settings.ts +++ b/src/editor/settings/settings.ts @@ -15,6 +15,7 @@ type SettingsObserver = Observer & { id: string; reload: (...args: unknown[]) => void; disconnect: () => void; + whenNothingPending: (callback: () => void) => void; }; editor.once('load', () => { @@ -158,6 +159,15 @@ editor.once('load', () => { } }); + // calls back once the server has every local change + settings.whenNothingPending = (callback) => { + if (doc) { + doc.whenNothingPending(callback); + } else { + callback(); + } + }; + settings.disconnect = function () { if (doc) { doc.destroy();