enabled speedy mode by default (#2373)

This commit is contained in:
Kuitos 2023-01-12 18:57:59 +08:00 committed by GitHub
parent 68d0e12bdb
commit 141d86807c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -26,13 +26,13 @@ it('should wrap the id [2]', () => {
it('should wrap string with div', () => { it('should wrap string with div', () => {
const tpl = '<span>qiankun</span>'; const tpl = '<span>qiankun</span>';
const factory = getDefaultTplWrapper('react16'); const factory = getDefaultTplWrapper('react16', { speedy: true });
const ret = factory(tpl); const ret = factory(tpl);
expect(ret).toBe( expect(ret).toBe(
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
`<div id="__qiankun_microapp_wrapper_for_react_16__" data-name="react16" data-version="${version}"><qiankun-head></qiankun-head>${tpl}</div>`, `<div id="__qiankun_microapp_wrapper_for_react_16__" data-name="react16" data-version="${version}" data-sandbox-configuration="{\"speedy\":true}"><qiankun-head></qiankun-head>${tpl}</div>`,
); );
}); });

View File

@ -272,7 +272,7 @@ export async function loadApp<T extends ObjectType>(
await (prevAppUnmountedDeferred && prevAppUnmountedDeferred.promise); await (prevAppUnmountedDeferred && prevAppUnmountedDeferred.promise);
} }
const appContent = getDefaultTplWrapper(appInstanceId)(template); const appContent = getDefaultTplWrapper(appInstanceId, sandbox)(template);
const strictStyleIsolation = typeof sandbox === 'object' && !!sandbox.strictStyleIsolation; const strictStyleIsolation = typeof sandbox === 'object' && !!sandbox.strictStyleIsolation;
@ -311,7 +311,8 @@ export async function loadApp<T extends ObjectType>(
let mountSandbox = () => Promise.resolve(); let mountSandbox = () => Promise.resolve();
let unmountSandbox = () => Promise.resolve(); let unmountSandbox = () => Promise.resolve();
const useLooseSandbox = typeof sandbox === 'object' && !!sandbox.loose; 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; let sandboxContainer;
if (sandbox) { if (sandbox) {
sandboxContainer = createSandboxContainer( sandboxContainer = createSandboxContainer(

View File

@ -130,7 +130,7 @@ export function isBoundedFunction(fn: CallableFunction) {
export const qiankunHeadTagName = 'qiankun-head'; export const qiankunHeadTagName = 'qiankun-head';
export function getDefaultTplWrapper(name: string) { export function getDefaultTplWrapper(name: string, sandboxOpts: FrameworkConfiguration['sandbox']) {
return (tpl: string) => { return (tpl: string) => {
let tplWithSimulatedHead: string; let tplWithSimulatedHead: string;
@ -146,7 +146,9 @@ export function getDefaultTplWrapper(name: string) {
return `<div id="${getWrapperId( return `<div id="${getWrapperId(
name, name,
)}" data-name="${name}" data-version="${version}">${tplWithSimulatedHead}</div>`; )}" data-name="${name}" data-version="${version}" data-sandbox-configuration="${JSON.stringify(
sandboxOpts,
)}">${tplWithSimulatedHead}</div>`;
}; };
} }