This is because when switching from project to editor view, this component gets unmounted and then remounted, but the componentDidMount seems to happen before the componentWillUnmount. Because it is dealing with a global variable, it is unsafe to always unset the beforeunload when unmounting.