Skip to content

Commit

Permalink
Fix the race
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed May 14, 2021
1 parent 6504a33 commit 6f594e6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/es-module-shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ async function topLevelLoad (url, source, polyfill) {
}

async function importShim (id, parentUrl = pageBaseUrl) {
console.log('importShim before await', id)
// Give dynamically inserted import maps a chance to be processed
// if `importShim()` was called synchronously after the insertion.
await new Promise(resolve => setTimeout(resolve, 0))
// Make sure all the "in-flight" import maps are loaded and applied.
await importMapPromise;
console.log('importShim after await', id)
return topLevelLoad(resolve(id, parentUrl).r || throwUnresolved(id, parentUrl));
}

Expand Down Expand Up @@ -294,7 +296,6 @@ new MutationObserver(mutations => {
if (mutation.type !== 'childList') continue;
for (const node of mutation.addedNodes) {
if (node.tagName === 'SCRIPT' && node.type)
console.log('MutationObserver', node.innerHTML)
processScript(node, !firstTopLevelProcess);
}
}
Expand All @@ -320,13 +321,11 @@ async function processScript (script, dynamic) {
importMapSrcOrLazy = true;
hasImportMap = true;
importMap = resolveAndComposeImportMap(script.src ? await (await fetchHook(script.src)).json() : JSON.parse(script.innerHTML), script.src || pageBaseUrl, importMap);
console.log('Processed', script.innerHTML)
});
}
}

function resolve (id, parentUrl) {
console.log("resolve", id)
const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl);
const resolved = resolveImportMap(importMap, urlResolved || id, parentUrl);
return { r: resolved, m: urlResolved !== resolved };
Expand Down

0 comments on commit 6f594e6

Please sign in to comment.