Skip to content

Commit

Permalink
fix: 补充上对于低版本umijs的适配
Browse files Browse the repository at this point in the history
如果umijs没有升级到这次提交[#6702](umijs/umi#6702), 则使用原来的处理方式
  • Loading branch information
futengda committed Jun 7, 2021
1 parent ce41646 commit a80e453
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-qiankun/src/slave/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function (api: IApi) {
try {
pluginArgs.appId = appId;
} catch {
console.error(\`plugin-qiankun: Cannot find pluginArgs object in current scope, please check if the umijs version is greater than xxx\`);
console.error(\`[@umijs/plugin-qiankun]: Cannot find pluginArgs object in current scope, plugin-qiankun will use an insecure way to handle the clientRenderOpts, see https://github.com/umijs/plugins/pull/629 for more information. \`);
}
`,
);
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-qiankun/src/slave/lifecycles.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ let hasMountedAtLeastOnce = false;

export default () => defer.promise;

const unsafe_clientRenderOptsStack: any[] = []; // 对于尚未更新到这次提交(https://github.com/umijs/umi/pull/6702)的umijs版本的适配,以后应该删掉
const clientRenderOptsMap: any = {};
export function getClientRenderOpts(appId: number) {
return { ...clientRenderOptsMap[appId] };
export function getClientRenderOpts(appId?: number) {
return typeof appId === 'number' ? { ...clientRenderOptsMap[appId] } : unsafe_clientRenderOptsStack.pop();
}

function normalizeHistory(
Expand Down Expand Up @@ -112,6 +113,7 @@ export function genMount(mountElementId: string, appId: number) {
},
};

unsafe_clientRenderOptsStack.push(clientRenderOpts);
clientRenderOptsMap[appId] = clientRenderOpts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const render = (oldRender: any) => {
return qiankunRender().then(oldRender);
};

export function modifyClientRenderOpts(memo: any, args: any) {
export function modifyClientRenderOpts(memo: any, args: any = {}) {
// 每次应用 render 的时候会调 modifyClientRenderOpts,这时根据当前的appId获取 render 的配置
const clientRenderOpts = getClientRenderOpts(args.appId);
if (clientRenderOpts) {
Expand Down

0 comments on commit a80e453

Please sign in to comment.