Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle inline scripts when systemjs itself is inline #2369

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/features/script-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,26 @@ systemJSPrototype.createScript = function (url) {
var lastAutoImportUrl, lastAutoImportDeps, lastAutoImportTimeout;
var autoImportCandidates = {};
var systemRegister = systemJSPrototype.register;
var inlineScriptCount = 0;
systemJSPrototype.register = function (deps, declare) {
if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
var scripts = document.querySelectorAll('script[src]');
var lastScript = scripts[scripts.length - 1];
if (lastScript) {
lastAutoImportDeps = deps;
if (lastScript && lastScript.src) {
lastAutoImportUrl = lastScript.src;
lastAutoImportDeps = deps;
// if this is already a System load, then the instantiate has already begun
// so this re-import has no consequence
var loader = this;
lastAutoImportTimeout = setTimeout(function () {
autoImportCandidates[lastScript.src] = [deps, declare];
loader.import(lastScript.src);
});
}
else {
inlineScriptCount++;
lastAutoImportUrl = document.location.href + "__inline_script__" + inlineScriptCount;
}
// if this is already a System load, then the instantiate has already begun
// so this re-import has no consequence
var loader = this;
lastAutoImportTimeout = setTimeout(function () {
autoImportCandidates[lastAutoImportUrl] = [deps, declare];
loader.import(lastAutoImportUrl);
});
}
else {
lastAutoImportDeps = undefined;
Expand Down