diff --git a/app/srv/ws/sync/editor/prep-page.ts b/app/srv/ws/sync/editor/prep-page.ts index 2e7549e4..fd86070f 100644 --- a/app/srv/ws/sync/editor/prep-page.ts +++ b/app/srv/ws/sync/editor/prep-page.ts @@ -51,53 +51,55 @@ export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => { const result = new Set(); const loading = {} as Record>; const should_save = {} as Record; - for (const child of ctree.childs) { - await initLoadComp( - { comps: mcomps, meta, mode: "page" }, - child as unknown as IItem, - { - visit(meta, item, shared) { - if (item.adv?.js) { - let script = undefined; - script = parseJs(item.adv.js); - if ( - !item.script || - Object.keys(script || {}).length !== - Object.keys(item.script || {}).length - ) { - shared.should_save = true; - item.script = script; - } - } - }, - async done(shared) { - if (shared.should_save && shared.root.component?.id) { - should_save[shared.root.component.id] = shared.root; - } - }, - load: async (comp_ids) => { - for (const id of comp_ids) { - if (!docs.comp[id]) { - if (typeof loading[id] === "undefined") { - loading[id] = new Promise(async (resolve) => { - await loadComponent(id, sync); - resolve(); - }); + if (ctree && ctree.childs) { + for (const child of ctree.childs) { + await initLoadComp( + { comps: mcomps, meta, mode: "page" }, + child as unknown as IItem, + { + visit(meta, item, shared) { + if (item.adv?.js) { + let script = undefined; + script = parseJs(item.adv.js); + if ( + !item.script || + Object.keys(script || {}).length !== + Object.keys(item.script || {}).length + ) { + shared.should_save = true; + item.script = script; } - await loading[id]; - } else { - userSyncComponent(sync, id); } + }, + async done(shared) { + if (shared.should_save && shared.root.component?.id) { + should_save[shared.root.component.id] = shared.root; + } + }, + load: async (comp_ids) => { + for (const id of comp_ids) { + if (!docs.comp[id]) { + if (typeof loading[id] === "undefined") { + loading[id] = new Promise(async (resolve) => { + await loadComponent(id, sync); + resolve(); + }); + } + await loading[id]; + } else { + userSyncComponent(sync, id); + } - result.add(id); - mcomps[id] = docs.comp[id].doc - .getMap("map") - .get("root") - ?.toJSON() as IItem; - } - }, - } - ); + result.add(id); + mcomps[id] = docs.comp[id].doc + .getMap("map") + .get("root") + ?.toJSON() as IItem; + } + }, + } + ); + } } if (Object.keys(should_save).length > 0) {