Skip to content
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

开启 keepalive 后,组件在路由跳转前重复执行了一次 useEffect #1021

Open
luhc228 opened this issue Nov 15, 2022 · 1 comment
Labels
Bug Something isn't working

Comments

@luhc228
Copy link
Contributor

luhc228 commented Nov 15, 2022

export default function Home() {
  useEffect(() => {
    console.log(1);         // will log twice
  }, [])
}
@luhc228 luhc228 added the Bug Something isn't working label Nov 15, 2022
@hzyhbk
Copy link

hzyhbk commented Nov 15, 2022

调试发现跟这行代码有关系 https://github.com/raxjs/rax-app/blob/master/packages/plugin-rax-router/src/runtime/KeepAliveRouter.tsx#L83 , 包了一层 Fragment 就会导致组件重新渲染。把 Fragment 换成 div 或者去掉就不会重新渲染了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants