Skip to content

Commit

Permalink
fix: prefer reading script.dataset.src in script load error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos committed Nov 29, 2023
1 parent f09c153 commit 22957c1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,23 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
) => {
script.onload = script.onerror = null;

// In order to avoid the inline script to be executed immediately after the prev onload is executed, resulting in the failure of the sandbox to obtain the latestSetProp, here we must resolve the entryScriptLoadedDeferred firstly
// entryScriptLoadedDeferred not resolved or rejected yet
if (!entryScriptLoadedDeferred.isSettled()) {
if (event.type === 'load') {
onEntryLoaded();
} else {
entryScriptLoadedDeferred.reject(
new QiankunError(`entry ${entry} load failed as entry script ${script.src} load failed}`),
new QiankunError(
`entry ${entry} load failed as entry script ${script.dataset.src || script.src} load failed}`,
),
);
}
}

/*
In order to avoid the inline script to be executed immediately after the prev onload is executed, resulting in the failure of the sandbox to obtain the latestSetProp
here we must resolve the entryScriptLoadedDeferred firstly and then execute the prevListener
*/
prevListener?.call(script, event);
};

Expand Down

0 comments on commit 22957c1

Please sign in to comment.