From 141d86807c18ea90bc3513d1024d10b0afc260ab Mon Sep 17 00:00:00 2001 From: Kuitos Date: Thu, 12 Jan 2023 18:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20enabled=20speedy=20mode=20by=20defa?= =?UTF-8?q?ult=20(#2373)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/utils.test.ts | 4 ++-- src/loader.ts | 5 +++-- src/utils.ts | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts index b73590416..469aa3d6f 100644 --- a/src/__tests__/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -26,13 +26,13 @@ it('should wrap the id [2]', () => { it('should wrap string with div', () => { const tpl = 'qiankun'; - const factory = getDefaultTplWrapper('react16'); + const factory = getDefaultTplWrapper('react16', { speedy: true }); const ret = factory(tpl); expect(ret).toBe( // eslint-disable-next-line max-len - `
${tpl}
`, + `
${tpl}
`, ); }); diff --git a/src/loader.ts b/src/loader.ts index 8ad2ec803..257653289 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -272,7 +272,7 @@ export async function loadApp( await (prevAppUnmountedDeferred && prevAppUnmountedDeferred.promise); } - const appContent = getDefaultTplWrapper(appInstanceId)(template); + const appContent = getDefaultTplWrapper(appInstanceId, sandbox)(template); const strictStyleIsolation = typeof sandbox === 'object' && !!sandbox.strictStyleIsolation; @@ -311,7 +311,8 @@ export async function loadApp( let mountSandbox = () => Promise.resolve(); let unmountSandbox = () => Promise.resolve(); const useLooseSandbox = typeof sandbox === 'object' && !!sandbox.loose; - const speedySandbox = typeof sandbox === 'object' && !!sandbox.speedy; + // enable speedy mode by default + const speedySandbox = typeof sandbox === 'object' ? sandbox.speedy !== false : true; let sandboxContainer; if (sandbox) { sandboxContainer = createSandboxContainer( diff --git a/src/utils.ts b/src/utils.ts index 5362f5f49..6464aaa21 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -130,7 +130,7 @@ export function isBoundedFunction(fn: CallableFunction) { export const qiankunHeadTagName = 'qiankun-head'; -export function getDefaultTplWrapper(name: string) { +export function getDefaultTplWrapper(name: string, sandboxOpts: FrameworkConfiguration['sandbox']) { return (tpl: string) => { let tplWithSimulatedHead: string; @@ -146,7 +146,9 @@ export function getDefaultTplWrapper(name: string) { return `
${tplWithSimulatedHead}
`; + )}" data-name="${name}" data-version="${version}" data-sandbox-configuration="${JSON.stringify( + sandboxOpts, + )}">${tplWithSimulatedHead}`; }; }