From 585d36d50505b0a452fb4e5fcab17bc3285ba65f Mon Sep 17 00:00:00 2001 From: Kuitos Date: Mon, 30 Aug 2021 20:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20auto=20downgrade=20configuration=20?= =?UTF-8?q?in=20unsupported=20environment=20for=20loadMicroApp=20api=20(#1?= =?UTF-8?q?681)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis.ts | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/apis.ts b/src/apis.ts index 5e5ed44..32d79c9 100644 --- a/src/apis.ts +++ b/src/apis.ts @@ -18,6 +18,25 @@ const defaultUrlRerouteOnly = true; const frameworkStartedDefer = new Deferred(); +const autoDowngradeForLowVersionBrowser = (configuration: FrameworkConfiguration): FrameworkConfiguration => { + const { sandbox, singular } = configuration; + if (sandbox) { + if (!window.Proxy) { + console.warn('[qiankun] Miss window.Proxy, proxySandbox will degenerate into snapshotSandbox'); + + if (singular === false) { + console.warn( + '[qiankun] Setting singular as false may cause unexpected behavior while your browser not support window.Proxy', + ); + } + + return { ...configuration, sandbox: typeof sandbox === 'object' ? { ...sandbox, loose: true } : { loose: true } }; + } + } + + return configuration; +}; + export function registerMicroApps( apps: Array>, lifeCycles?: FrameworkLifeCycles, @@ -114,7 +133,9 @@ export function loadMicroApp( * the micro app would not load and evaluate its lifecycles again */ const memorizedLoadingFn = async (): Promise => { - const userConfiguration = configuration ?? { ...frameworkConfiguration, singular: false }; + const userConfiguration = autoDowngradeForLowVersionBrowser( + configuration ?? { ...frameworkConfiguration, singular: false }, + ); const { $$cacheLifecycleByAppName } = userConfiguration; const container = 'container' in app ? app.container : undefined; @@ -196,17 +217,7 @@ export function start(opts: FrameworkConfiguration = {}) { doPrefetchStrategy(microApps, prefetch, importEntryOpts); } - if (sandbox) { - if (!window.Proxy) { - console.warn('[qiankun] Miss window.Proxy, proxySandbox will degenerate into snapshotSandbox'); - frameworkConfiguration.sandbox = typeof sandbox === 'object' ? { ...sandbox, loose: true } : { loose: true }; - if (!singular) { - console.warn( - '[qiankun] Setting singular as false may cause unexpected behavior while your browser not support window.Proxy', - ); - } - } - } + frameworkConfiguration = autoDowngradeForLowVersionBrowser(frameworkConfiguration); startSingleSpa({ urlRerouteOnly }); started = true;