diff --git a/package.json b/package.json index 7a5dd1d..bf0cace 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "homepage": "https://github.com/kuitos/qiankun#readme", "dependencies": { "@babel/runtime": "^7.10.5", - "import-html-entry": "^1.8.1", + "import-html-entry": "^1.9.0", "lodash": "^4.17.11", "single-spa": "^5.3.1", "tslib": "^1.10.0" diff --git a/src/sandbox/patchers/dynamicAppend.ts b/src/sandbox/patchers/dynamicAppend.ts index 9fc2c7e..559db60 100644 --- a/src/sandbox/patchers/dynamicAppend.ts +++ b/src/sandbox/patchers/dynamicAppend.ts @@ -76,7 +76,7 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { newChild: T, refChild?: Node | null, ) { - const element = newChild as any; + let element = newChild as any; const { rawDOMAppendOrInsertBefore } = opts; if (element.tagName) { // eslint-disable-next-line prefer-const @@ -152,6 +152,14 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { execScripts(null, [src], proxy, { fetch, strictGlobal: !singular, + beforeExec: () => { + Object.defineProperty(document, 'currentScript', { + get(): any { + return element; + }, + configurable: true, + }); + }, success: () => { // we need to invoke the onload event manually to notify the event listener that the script was completed // here are the two typical ways of dynamic script loading @@ -163,6 +171,8 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { } else { element.dispatchEvent(loadEvent); } + + element = null; }, error: () => { const errorEvent = new CustomEvent('error'); @@ -171,6 +181,8 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { } else { element.dispatchEvent(errorEvent); } + + element = null; }, });