Skip to content

Commit f56eeb4

Browse files
committed
fix(loader): better resourceUrl resolution
1 parent 0c933a4 commit f56eeb4

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/compiler/component-lazy/generate-lazy-app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ function getLegacyLoader(config: d.Config) {
137137
var scriptElm = doc.createElement('script');
138138
scriptElm.setAttribute('type', 'module');
139139
scriptElm.src = url + '/${namespace}.esm.js';
140-
doc.head.appendChild(scriptElm);
141140
warn.push(scriptElm.outerHTML);
141+
scriptElm.setAttribute('data-stencil-namespace', '${namespace}');
142+
doc.head.appendChild(scriptElm);
142143
143144
scriptElm = doc.createElement('script');
144145
scriptElm.setAttribute('nomodule', '');
145146
scriptElm.src = url + '/${namespace}.js';
146147
warn.push(scriptElm.outerHTML);
147-
148148
scriptElm.setAttribute('data-stencil-namespace', '${namespace}');
149149
doc.head.appendChild(scriptElm);
150150

src/compiler/component-lazy/generate-system.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,17 @@ async function getSystemLoader(config: d.Config, corePath: string, includePolyfi
4848
(function () {
4949
var doc = document;
5050
var currentScript = doc.currentScript;
51+
52+
// Safari 10 support type="module" but still download and executes the nomodule script
5153
if (!currentScript || !currentScript.hasAttribute('nomodule') || !('onbeforeload' in currentScript)) {
5254
5355
${polyfills}
5456
55-
var scriptElm = doc.querySelector('script[data-stencil-namespace="${config.fsNamespace}"]');
56-
if (!scriptElm) {
57-
var allScripts = doc.querySelectorAll('script');
58-
for (var x = allScripts.length - 1; x >= 0; x--) {
59-
scriptElm = allScripts[x];
60-
if (scriptElm.src || scriptElm.hasAttribute('data-resources-url')) {
61-
break;
62-
}
63-
}
64-
}
57+
// Figure out currentScript (for IE11, since it does not support currentScript)
58+
var regex = /\\/${config.fsNamespace}(\\.esm)?\\.js($|\\?|#)/;
59+
var scriptElm = currentScript || Array.from(doc.querySelectorAll('script')).find(function(s) {
60+
return regex.test(s.src) || s.getAttribute('data-stencil-namespace') === "${config.fsNamespace}";
61+
});
6562
6663
var resourcesUrl = scriptElm ? scriptElm.getAttribute('data-resources-url') || scriptElm.src : '';
6764
var start = function() {

0 commit comments

Comments
 (0)