From 843b92c3423baf7555928f709bf74d8c4affbe6f Mon Sep 17 00:00:00 2001 From: Kuitos Date: Thu, 27 Aug 2020 16:13:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20dynamic=20append=20script?= =?UTF-8?q?=20with=20excludeAssetsFilter=20issue=20(#900)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/patchers/dynamicAppend.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/sandbox/patchers/dynamicAppend.ts b/src/sandbox/patchers/dynamicAppend.ts index 559db60..710d172 100644 --- a/src/sandbox/patchers/dynamicAppend.ts +++ b/src/sandbox/patchers/dynamicAppend.ts @@ -112,15 +112,12 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { case LINK_TAG_NAME: case STYLE_TAG_NAME: { const stylesheetElement: HTMLLinkElement | HTMLStyleElement = newChild as any; - if (!invokedByMicroApp) { + const { href } = stylesheetElement as HTMLLinkElement; + if (!invokedByMicroApp || (excludeAssetFilter && href && excludeAssetFilter(href))) { return rawDOMAppendOrInsertBefore.call(this, element, refChild) as T; } const mountDOM = appWrapperGetter(); - const { href } = stylesheetElement as HTMLLinkElement; - if (excludeAssetFilter && href && excludeAssetFilter(href)) { - return rawDOMAppendOrInsertBefore.call(mountDOM, element, refChild) as T; - } if (scopedCSS) { css.process(mountDOM, stylesheetElement, appName); @@ -133,18 +130,13 @@ function getOverwrittenAppendChildOrInsertBefore(opts: { } case SCRIPT_TAG_NAME: { - if (!invokedByMicroApp) { + const { src, text } = element as HTMLScriptElement; + // some script like jsonp maybe not support cors which should't use execScripts + if (!invokedByMicroApp || (excludeAssetFilter && src && excludeAssetFilter(src))) { return rawDOMAppendOrInsertBefore.call(this, element, refChild) as T; } const mountDOM = appWrapperGetter(); - const { src, text } = element as HTMLScriptElement; - - // some script like jsonp maybe not support cors which should't use execScripts - if (excludeAssetFilter && src && excludeAssetFilter(src)) { - return rawDOMAppendOrInsertBefore.call(mountDOM, element, refChild) as T; - } - const { fetch } = frameworkConfiguration; const referenceNode = mountDOM.contains(refChild) ? refChild : null;