Skip to content

Commit

Permalink
✨ enabled speedy mode by default (#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos authored Jan 12, 2023
1 parent 68d0e12 commit 141d868
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ it('should wrap the id [2]', () => {

it('should wrap string with div', () => {
const tpl = '<span>qiankun</span>';
const factory = getDefaultTplWrapper('react16');
const factory = getDefaultTplWrapper('react16', { speedy: true });

const ret = factory(tpl);

expect(ret).toBe(
// 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>`,
);
});

Expand Down
5 changes: 3 additions & 2 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export async function loadApp<T extends ObjectType>(
await (prevAppUnmountedDeferred && prevAppUnmountedDeferred.promise);
}

const appContent = getDefaultTplWrapper(appInstanceId)(template);
const appContent = getDefaultTplWrapper(appInstanceId, sandbox)(template);

const strictStyleIsolation = typeof sandbox === 'object' && !!sandbox.strictStyleIsolation;

Expand Down Expand Up @@ -311,7 +311,8 @@ export async function loadApp<T extends ObjectType>(
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(
Expand Down
6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -146,7 +146,9 @@ export function getDefaultTplWrapper(name: string) {

return `<div id="${getWrapperId(
name,
)}" data-name="${name}" data-version="${version}">${tplWithSimulatedHead}</div>`;
)}" data-name="${name}" data-version="${version}" data-sandbox-configuration="${JSON.stringify(
sandboxOpts,
)}">${tplWithSimulatedHead}</div>`;
};
}

Expand Down

1 comment on commit 141d868

@vercel
Copy link

@vercel vercel bot commented on 141d868 Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.