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

fix: memory leaks of Pull when refresh state is success or load state is failure. #488

Merged
merged 2 commits into from Aug 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/pull/Pull.tsx
Expand Up @@ -22,6 +22,8 @@ export default class Pull extends PureComponent<PullProps, any> {

private wrapTouchstartY;

private mounted = true;

static defaultProps: PullProps = {
prefixCls: 'za-pull',
refresh: {
Expand Down Expand Up @@ -49,6 +51,7 @@ export default class Pull extends PureComponent<PullProps, any> {
}

componentDidMount() {
this.mounted = true;
this.addScrollEvent();
Events.on(this.wrap, 'touchstart', this.wrapTouchstart);
Events.on(this.wrap, 'touchmove', this.wrapTouchmove);
Expand Down Expand Up @@ -89,6 +92,7 @@ export default class Pull extends PureComponent<PullProps, any> {
}

componentWillUnmount() {
this.mounted = false;
const scroller = (this.wrap === document.documentElement) ? window : this.wrap;
Events.off(scroller, 'scroll', this.throttledScroll);
Events.off(this.wrap, 'touchstart', this.wrapTouchstart);
Expand Down Expand Up @@ -260,6 +264,7 @@ export default class Pull extends PureComponent<PullProps, any> {
case REFRESH_STATE.failure:
this.doTransition({ offsetY: 'auto', animationDuration });
setTimeout(() => {
if (!this.mounted) return;
this.doRefreshAction(REFRESH_STATE.normal);
this.doLoadAction(LOAD_STATE.normal);
}, stayTime);
Expand All @@ -285,6 +290,7 @@ export default class Pull extends PureComponent<PullProps, any> {

case LOAD_STATE.failure:
setTimeout(() => {
if (!this.mounted) return;
this.doLoadAction(LOAD_STATE.abort);
}, stayTime);
break;
Expand Down