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

Affix 组件event listener 未被正确移除 #4755

Closed
skordyr opened this issue Feb 4, 2017 · 3 comments · Fixed by #4756
Closed

Affix 组件event listener 未被正确移除 #4755

skordyr opened this issue Feb 4, 2017 · 3 comments · Fixed by #4756
Assignees

Comments

@skordyr
Copy link

skordyr commented Feb 4, 2017

Environment(required)

  • antd version: 2.6.4
  • OS and its version: win10
  • Browser and its version: chrome 56.0.2924.87 (64-bit)

What did you do? Please provide steps to re-produce your problem.

  1. 父容器使用callback的ref方式获取dom node 通过context 传递给子组件
  2. 子组件通过context获取可scroll的dom node 传入Affix组件
  3. Affix 组件在componentDidMount中延迟了scroll和resize事件的监听
  4. 随后 组件在componentWillRecevieProps中再次监听了事件(此时didMount中的监听没执行,调用clearScrollEventListeners此时并没有达到预期效果),导致最后重复监听了事件
  5. 结果Affix unmount 后监听器依然存在(原因不明),导致react报错:findDOMNode was called on an unmounted component.

What do you expected?

期望事件被正确监听一次,Affix unmount后事件正确被移除
尝试在setTargetEventListeners监听事件前调用clearScrollEventListeners,结果符合预期

@jiangxy
Copy link

jiangxy commented Feb 4, 2017

我也碰到了这个问题,提供一个测试页面:http://jiangxy.github.io/ant-debug
只要在有affix/无affix两个组件中来回切换几次后再尝试滚动页面,就会出现大量findDOMNode was called on an unmounted component.错误日志

不过我传给Affix的target不是通过ref方式获取的,而是直接document.getElement

如果将antd版本换成1.11.0就正常了

@skordyr
Copy link
Author

skordyr commented Feb 4, 2017

你的这个原因也是因为didMount里面监听被延迟导致该监听晚于willReceive里面的监听使得重复监听了,移除的时候只移除了最后一次的,前面的被保留了,后来每次切换监听器的数量在不断增加,尝试我说的那个方法修改affix的源码应该能解决问题

RaoHai added a commit to RaoHai/ant-design that referenced this issue Feb 7, 2017
 + close ant-design#4755
 + close ant-design#4760
 + clearScrollEventListeners before setTargetEventListeners
 + add tests for throttle
 + append affix test case
ddcat1115 pushed a commit that referenced this issue Feb 8, 2017
*  Affix listener bug fix

 + close #4755
 + close #4760
 + clearScrollEventListeners before setTargetEventListeners
 + add tests for throttle
 + append affix test case

*  genMockFn -> fn()
@lock
Copy link

lock bot commented May 2, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants