diff --git a/.changeset/shiny-jeans-sip.md b/.changeset/shiny-jeans-sip.md new file mode 100644 index 000000000..c1df66926 --- /dev/null +++ b/.changeset/shiny-jeans-sip.md @@ -0,0 +1,5 @@ +--- +"qiankun": patch +--- + +feat: make loadEntry and beforeLoad runs parallelly diff --git a/packages/qiankun/src/core/loadApp.ts b/packages/qiankun/src/core/loadApp.ts index c946433a9..77efe22c7 100644 --- a/packages/qiankun/src/core/loadApp.ts +++ b/packages/qiankun/src/core/loadApp.ts @@ -58,6 +58,8 @@ export default async function loadApp( const containerOpts: LoaderOpts = { fetch, sandbox: sandboxInstance, transformer }; + const lifecyclesPromise = loadEntry(entry, microAppContainer, containerOpts); + const assetPublicPath = calcPublicPath(entry); const { beforeUnmount = [], @@ -68,9 +70,10 @@ export default async function loadApp( } = mergeWith({}, getAddOns(global, assetPublicPath), lifeCycles, (v1, v2) => concat((v1 ?? []) as LifeCycleFn, (v2 ?? []) as LifeCycleFn), ); + // 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(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,