Closed hyzx86 closed 1 year ago
由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。
给一个会丢失的最小复现看看。
复现我在做。。但是编译不过去-- 在 antdPro 项目上做的
async function getSettings(): Promise<Partial<LayoutSettings>> {
return {
...defaultSettings,
title: '张三李四王麻子',
} as Partial<LayoutSettings>;
}
/**
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* */
export async function getInitialState(): Promise<{
settings?: Partial<LayoutSettings>;
currentUser?: API.CurrentUser;
loading?: boolean;
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
}> {
const fetchUserInfo = async () => {
try {
const msg = await queryCurrentUser({
skipErrorHandler: true,
});
return msg.data;
} catch (error) {
history.push(loginPath);
}
return undefined;
};
// 如果不是登录页面,执行
const { location } = history;
if (location.pathname !== loginPath) {
const currentUser = await fetchUserInfo();
return {
fetchUserInfo,
currentUser,
settings: await getSettings(),
};
}
return {
fetchUserInfo,
settings: await getSettings(),
};
}
// app.tsx
childrenRender: (children) => {
// if (initialState?.loading) return <PageLoading />;
return (
<>
{children}
{isDev && (
<SettingDrawer
disableUrlParams
enableDarkTheme
settings={initialState?.settings}
onSettingChange={(settings) => {
// 🟡 添加完 title 之后,settings 变了,触发了 on change 事件,接下文
setInitialState((preInitialState) => ({
...preInitialState,
settings,
}));
}}
/>
)}
</>
);
},
感谢!
我希望可以通过服务端设置站点名称 在 getInitalState 方法里 返回了settings 并根据服务端配置 修改了 settings 中的 主题配置 等 runtimeConfig 信息
AntdPro 代码示例
在 app.tsx 中如下位置 输出 initialState
输出了5次,最后一次输出 的时候 title属性没了~~ 请问这是什么原因?我在源码里面找也没找到怎么回事~~
最小复现: https://github.com/ant-design/ant-design-pro/compare/master...hyzx86:ant-design-pro:titleLost