Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make loadEntry and beforeLoad runs parallelly #2749

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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