fix $loadScript/$loadStylesheet race condition - CR

This commit is contained in:
Andrea Vos 2024-07-08 20:16:39 +02:00
parent 2a5399d5a3
commit 54767c7c26

View File

@ -125,6 +125,7 @@ const plugin: Plugin = ({ app, store }, inject) => {
resolve();
});
script.addEventListener('error', (event) => {
script.classList.add('loaded'); // not really loaded, but let's stop other calls from waiting forever, see !493
reject(new LoadScriptError(name, src, typeof event === 'string' ? event : event.type));
});
document.body.appendChild(script);
@ -149,8 +150,12 @@ const plugin: Plugin = ({ app, store }, inject) => {
link.setAttribute('href', src);
link.classList.add(`${name}-stylesheet`);
link.crossOrigin = 'true';
link.addEventListener('load', () => resolve());
link.addEventListener('load', () => {
link.classList.add('loaded');
resolve();
});
link.addEventListener('error', (event) => {
link.classList.add('loaded'); // not really loaded, but let's stop other calls from waiting forever, see !493
reject(new LoadScriptError(name, src, typeof event === 'string' ? event : event.type));
});
document.body.appendChild(link);