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

🐛[BUG]useDeepCompareMemoize中使用isEqual来进行深比较会出现infinite loop的情况 #461

Closed
migodev42 opened this issue Sep 11, 2020 · 6 comments · Fixed by #527
Labels
⭕️ bug Something isn't working 🚩 good first issue Good for newcomers table

Comments

@migodev42
Copy link
Contributor

🐛 bug 描述

useDeepCompareMemoize中使用isEqual来进行深比较会出现infinite loop的情况

📷 复现步骤

在dev环境开发时,偶尔出现页面直接卡死的情况,使用chrome开发者工具查看调用堆栈发现isEqual一直循环调用。
bug

🏞 期望结果

💻 复现代码

© 版本信息

  • ProComponents 版本: latest
  • umi 版本 2.12.5
  • 浏览器环境 chrome 85.0.4183.102
  • 开发环境 ubuntu20.04

🚑 其他信息

参考react-use实现的useDeepCompareMemoize中使用的是fast-deep-equal的react版本特殊处理的isEqual。

处理了react元素比较时候的循环引用问题:
Screenshot from 2020-09-11 11-14-37

@chenshuai2144
Copy link
Contributor

有兴趣来个 pr 吗?

@chenshuai2144 chenshuai2144 added table ⭕️ bug Something isn't working 🚩 good first issue Good for newcomers labels Sep 11, 2020
@migodev42
Copy link
Contributor Author

我在自己的项目中是直接copy了fast-deep-equal的react版本实现,关键代码其实就是这块Screenshot from 2020-09-11 11-14-37在开源项目中不知道怎么处理比较好?1 直使用引用fast-deep-equal的react版本 2 拷贝fast-deep-equal的实现到项目中

还有个思路就是用lodash的isEqualWith自定义一个react版本的实现

@migodev42
Copy link
Contributor Author

补充信息:React会在dev环境添加一个_owner属性
Screenshot from 2020-09-11 14-26-21

@chenshuai2144
Copy link
Contributor

@LeoooY 这个库的大小能解决,直接依赖好了
https://www.npmjs.com/package/fast-deep-equal

@migodev42
Copy link
Contributor Author

在react下提了同样的issue,dan的建议是不要将两个react元素做深比较,对性能上好像有些影响
facebook/react#19811

@chenshuai2144
Copy link
Contributor

@LeoooY 我们没办法控制 用户的 icon 是不是 ReactNode, 可以自定义一下如果是 ReactNode 直接忽略一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭕️ bug Something isn't working 🚩 good first issue Good for newcomers table
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants