Skip to content

Commit

Permalink
feat: make loadEntry and beforeLoad runs parallelly (#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos authored Oct 23, 2023
1 parent 317961e commit e448082
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shiny-jeans-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"qiankun": patch
---

feat: make loadEntry and beforeLoad runs parallelly
5 changes: 4 additions & 1 deletion packages/qiankun/src/core/loadApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export default async function loadApp<T extends ObjectType>(

const containerOpts: LoaderOpts = { fetch, sandbox: sandboxInstance, transformer };

const lifecyclesPromise = loadEntry<MicroAppLifeCycles>(entry, microAppContainer, containerOpts);

const assetPublicPath = calcPublicPath(entry);
const {
beforeUnmount = [],
Expand All @@ -68,9 +70,10 @@ export default async function loadApp<T extends ObjectType>(
} = mergeWith({}, getAddOns(global, assetPublicPath), lifeCycles, (v1, v2) =>
concat((v1 ?? []) as LifeCycleFn<T>, (v2 ?? []) as LifeCycleFn<T>),
);
// FIXME Due to the asynchronous execution of loadEntry, the DOM of the sub-app is inserted synchronously through appendChild, and inline scripts are also executed synchronously. Therefore, the beforeLoad may need to rely on transformer configuration to coordinate and ensure the order of asynchronous operations.
await execHooksChain(toArray(beforeLoad), app, global);

const lifecycles = await loadEntry<MicroAppLifeCycles>(entry, microAppContainer, containerOpts);
const lifecycles = await lifecyclesPromise;
if (!lifecycles) throw new QiankunError(`${appName} entry ${entry} load failed as it not export lifecycles`);
const { bootstrap, mount, unmount, update } = getLifecyclesFromExports(
lifecycles,
Expand Down

0 comments on commit e448082

Please sign in to comment.