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 leak warning, clear timer when the component unmounts #6641

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions frontend/src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Alert from './alert';
const ANIMATION_DURATION = 240;

export default class Toast extends React.PureComponent {
_isMounted = false;

static propTypes = {
/**
* The z-index of the toast.
Expand Down Expand Up @@ -67,10 +69,12 @@ export default class Toast extends React.PureComponent {
}

componentDidMount() {
this._isMounted = true;
this.startCloseTimer();
}

componentWillUnmount() {
this._isMounted = false;
this.clearCloseTimer();
}

Expand All @@ -80,9 +84,11 @@ export default class Toast extends React.PureComponent {
event.stopPropagation();
}
this.clearCloseTimer();
this.setState({
isShown: false
});
if (this._isMounted) {
this.setState({
isShown: false
});
}
};

startCloseTimer = () => {
Expand Down
Loading