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 authored Nov 29, 2023
1 parent f09c153 commit 2e528c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-pots-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@qiankunjs/loader": patch
---

fix: prefer reading script.dataset.src in script load error message
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 2e528c9

Please sign in to comment.