8000 layouts文件state状态改变时,在以下情况下会触发pages页面重新 mount · Issue #1129 · umijs/umi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

layouts文件state状态改变时,在以下情况下会触发pages页面重新 mount #1129

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

Closed
SwordsmanYao opened this issue Sep 25, 2018 · 2 comments

Comments

@SwordsmanYao
Copy link
Contributor
SwordsmanYao commented Sep 25, 2018

复现条件:
1.layouts中使用 antd 的 Layout组件
2.pages对应目录下有 _layout.tsx 文件

删除 antd 的 Layout组件 或 删除 _layout.tsx 文件,都不会出现此问题

复现demo: https://github.com/SwordsmanYao/kmx-ui-next-platform/tree/issue-layout
操作:
1.进到 http://localhost:8000/list
2.点击‘转换’按钮
结果:
列表被重新加载了
期望:
列表不会重新加载

@dilidili
Copy link
Contributor

我觉得这个应该是由于 antd 的 Layout 组件是一个 ContextProvider, 而 React 在 updateClassInstance 的过程中默认 context 总是被修改过:

  // The context might have changed so we need to recalculate it.
  if (hasContext) {
    invalidateContextProvider(workInProgress, Component, true);
  }

导致 children 全部被重绘。再加上 list/_layout 中使用了鉴权路由造成的 Component 重建,最后导致了重新 mount。

一种解决方案就是把 Layout 组件放到 state update 影响不到的地方,比如:
https://github.com/SwordsmanYao/kmx-ui-next-platform/blob/issue-layout/src/layouts/index.tsx

export default withRouter(connect()((props) => <Layout><Layouts {...props} /></Layout>));

@SwordsmanYao
Copy link
Contributor Author

@dilidili 布局里用了两个 Layout,拿不出来的,看看后面如果解不了的话只能改成 div自己写了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0