From 879b13a330a832645f80fb27cfa5569b2769f5e8 Mon Sep 17 00:00:00 2001 From: maoxiaoke Date: Tue, 28 Sep 2021 12:09:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20=F0=9F=A4=96=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2112e8c7..9a76f30a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ice/stark", - "version": "2.6.1", + "version": "2.6.2", "description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.", "scripts": { "install:deps": "rm -rf node_modules && rm -rf ./packages/*/node_modules && yarn install && lerna exec -- npm install", From bf091a3184a406096ce75288a8dcdf6ef38274fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=A3=E5=90=92?= Date: Thu, 14 Oct 2021 15:38:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20prevent=20duplicate?= =?UTF-8?q?=20appends=20some=20resources=20(#372)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 prevent duplicate appends some resources --- src/util/handleAssets.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/util/handleAssets.ts b/src/util/handleAssets.ts index d2b7e431..b0f96275 100644 --- a/src/util/handleAssets.ts +++ b/src/util/handleAssets.ts @@ -57,6 +57,21 @@ export interface ILifecycleProps { customProps?: object; } +function isAssetExist(element: HTMLScriptElement | HTMLLIElement, type: 'script' | 'link') { + const urlAlias = type === 'script' ? 'src' : 'href'; + + return Array.from(document.getElementsByTagName(type)) + .some((item) => { + if ( + item[urlAlias] + && element[urlAlias] === item[urlAlias] + ) { + return true; + } + return false; + }); +} + /** * Create link/style element and append to root */ @@ -235,6 +250,10 @@ export function appendExternalScript(asset: string | Asset, scriptAttributes, }); + if (isAssetExist(element, 'script')) { + resolve(); + } + element.addEventListener( 'error', () => reject(new Error(`js asset loaded error: ${content || asset}`)), From 540b6b02ecc0b439ef60a6a9afbfc0375da3ba21 Mon Sep 17 00:00:00 2001 From: maoxiaoke Date: Thu, 14 Oct 2021 17:18:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20catch=20javascript=20?= =?UTF-8?q?runtime=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/handleAssets.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/handleAssets.ts b/src/util/handleAssets.ts index d2b7e431..03944922 100644 --- a/src/util/handleAssets.ts +++ b/src/util/handleAssets.ts @@ -235,6 +235,20 @@ export function appendExternalScript(asset: string | Asset, scriptAttributes, }); + /** + * For JavaScript runtime error may not fire error event (https://github.com/ice-lab/icestark/issues/419). + * While window.onerror is supported to catch JavaScript runtime error. + */ + const rejectRuntimeError = (event: ErrorEvent) => { + if (event?.filename === (content || asset)) { + reject(new Error(`js asset runtime error: ${event?.message}`)); + } + + window.removeEventListener('error', rejectRuntimeError); + }; + + window.addEventListener('error', rejectRuntimeError); + element.addEventListener( 'error', () => reject(new Error(`js asset loaded error: ${content || asset}`)),