Skip to content

Commit

Permalink
fix: history is undefined on render (#9871)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Dec 8, 2022
1 parent 34d223a commit c4465e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
10 changes: 9 additions & 1 deletion packages/plugins/libs/qiankun/slave/slaveRuntimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// @ts-nocheck
import qiankunRender, { contextOptsStack } from './lifecycles';
import { createHistory } from '@@/core/history';

export function render(oldRender: any) {
return qiankunRender().then(oldRender);
}

export function modifyContextOpts(memo: any) {
export function modifyClientRenderOpts(memo: any) {
// 每次应用 render 的时候会调 modifyClientRenderOpts,这时尝试从队列中取 render 的配置
const clientRenderOpts = contextOptsStack.shift();
if (clientRenderOpts) {
clientRenderOpts.history = createHistory({
type: clientRenderOpts.historyType,
basename: clientRenderOpts.basename,
...clientRenderOpts.historyOpts,
});
}
return {
...memo,
...clientRenderOpts,
Expand Down
26 changes: 15 additions & 11 deletions packages/preset-umi/templates/umi.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,24 @@ async function render() {
},
});

const contextOpts = pluginManager.applyPlugins({
key: 'modifyContextOpts',
type: ApplyPluginsType.modify,
initialValue: {},
});

const basename = contextOpts.basename || '{{{ basename }}}';

const history = createHistory({
type: contextOpts.historyType || '{{{ historyType }}}',
basename,
...contextOpts.historyOpts,
});

return (pluginManager.applyPlugins({
key: 'render',
type: ApplyPluginsType.compose,
initialValue() {
const contextOpts = pluginManager.applyPlugins({
key: 'modifyContextOpts',
type: ApplyPluginsType.modify,
initialValue: {},
});
const basename = contextOpts.basename || '{{{ basename }}}';
const context = {
{{#hydrate}}
hydrate: true,
Expand All @@ -53,11 +61,7 @@ async function render() {
{{/loadingComponent}}
publicPath,
runtimePublicPath,
history: createHistory({
type: contextOpts.historyType || '{{{ historyType }}}',
basename,
...contextOpts.historyOpts,
}),
history,
basename,
callback: contextOpts.callback,
};
Expand Down

0 comments on commit c4465e0

Please sign in to comment.