fix: plugin-qiankun修复主应用更新props不触发update

This commit is contained in:
wanchun 2022-05-09 14:07:25 +08:00
parent baff9073c4
commit c0cc29da44

View File

@ -64,13 +64,11 @@ export const MicroApp = defineComponent({
return {}; return {};
}); });
const propsFromParams = attrs;
const propsConfigRef = computed(() => { const propsConfigRef = computed(() => {
return { return {
...propsFromConfigRef.value, ...propsFromConfigRef.value,
...props.props, ...props.props,
...propsFromParams ...attrs
}; };
}); });
@ -85,7 +83,7 @@ export const MicroApp = defineComponent({
name: `${name}_${Date.now()}`, name: `${name}_${Date.now()}`,
entry: entry, entry: entry,
container: containerRef.value, container: containerRef.value,
props: propsConfigRef.value props: {...propsConfigRef.value}
}, },
{ {
...globalSettings, ...globalSettings,
@ -107,37 +105,36 @@ export const MicroApp = defineComponent({
if (!updatingPromiseRef.value) { if (!updatingPromiseRef.value) {
// 初始化 updatingPromiseRef 为 microApp.mountPromise从而确保后续更新是在应用 mount 完成之后 // 初始化 updatingPromiseRef 为 microApp.mountPromise从而确保后续更新是在应用 mount 完成之后
updatingPromiseRef.value = microApp.mountPromise; updatingPromiseRef.value = microApp.mountPromise;
} else { }
// 确保 microApp.update 调用是跟组件状态变更顺序一致的,且后一个微应用更新必须等待前一个更新完成 // 确保 microApp.update 调用是跟组件状态变更顺序一致的,且后一个微应用更新必须等待前一个更新完成
updatingPromiseRef.value = updatingPromiseRef.value.then( updatingPromiseRef.value = updatingPromiseRef.value.then(
() => { () => {
const canUpdate = (app) => const canUpdate = (app) =>
app?.update && app.getStatus() === 'MOUNTED'; app?.update && app.getStatus() === 'MOUNTED';
if (canUpdate(microApp)) { if (canUpdate(microApp)) {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
if ( if (
Date.now() - Date.now() -
updatingTimestampRef.value < updatingTimestampRef.value <
200 200
) { ) {
console.warn( console.warn(
`[@fesjs/plugin-qiankun] It seems like microApp ${props.name} is updating too many times in a short time(200ms), you may need to do some optimization to avoid the unnecessary re-rendering.` `[@fesjs/plugin-qiankun] It seems like microApp ${props.name} is updating too many times in a short time(200ms), you may need to do some optimization to avoid the unnecessary re-rendering.`
);
}
console.info(
`[@fesjs/plugin-qiankun] MicroApp ${props.name} is updating with props: `,
props
); );
updatingTimestampRef.value = Date.now();
} }
// 返回 microApp.update 形成链式调用 console.info(
return microApp.update(propsConfigRef.value); `[@fesjs/plugin-qiankun] MicroApp ${props.name} is updating with props: `,
props
);
updatingTimestampRef.value = Date.now();
} }
// 返回 microApp.update 形成链式调用
return microApp.update({...propsConfigRef.value});
} }
); }
} );
} }
}; };