-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复 icestark App router prefetch 功能 #732
base: master
Are you sure you want to change the base?
Conversation
@@ -113,6 +111,24 @@ export default class AppRouter extends React.Component<AppRouterProps, AppRouter | |||
this.setState({ started: false }); | |||
} | |||
|
|||
componentWillReceiveProps(nextProps: Readonly<AppRouterProps>, nextContext: any): void { | |||
if (nextProps.apps !== this.props.apps) { | |||
this.tryPrefetch(nextProps); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 componentWillReceiveProps 阶段会存在多次执行的情况,需要增加额外机制判断 apps / url 信息是否已完成预加载
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -35,6 +35,8 @@ export interface AppRouterProps { | |||
basename?: string; | |||
fetch?: Fetch; | |||
prefetch?: Prefetch; | |||
apps?: AppConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不增加额外参数,直接以 children 上的信息进行判断是不是也可以
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也行,可以做到 didupdate 里面,我找时间改下
现象:配置 approuter prefetch 后,实际未预加载微应用 router 相关资源
原因定位:AppRouter 内部在 construct 时,解析 React.children,进行微应用的 prefetch,这要求在 AppRouter 在构建时就需要提供所有微应用的 child。
修复方式:修改 @ice/plugin-icestark 插件中,对 AppRouter 的渲染方式,传入 apps,在 AppRouter 中,判定 apps 变化,做 prefetch。
构造方法时 prefetch
https://github.com/ice-lab/icestark/blob/master/packages/icestark/src/AppRouter.tsx#L79
依赖 child
https://github.com/ice-lab/icestark/blob/master/packages/icestark/src/AppRouter.tsx#L121
插件渲染时机
https://github.com/alibaba/ice/blob/master/packages/plugin-icestark/src/runtime/framework.tsx#L48