From c492602a9f632fef5171367a6130318347633600 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 19 Dec 2018 16:37:32 -0500 Subject: [PATCH] Do not remove the window beforeunload handler in componentWillUnmount. 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. --- src/lib/project-saver-hoc.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/project-saver-hoc.jsx b/src/lib/project-saver-hoc.jsx index 44a47540a..6e6848e92 100644 --- a/src/lib/project-saver-hoc.jsx +++ b/src/lib/project-saver-hoc.jsx @@ -100,7 +100,10 @@ const ProjectSaverHOC = function (WrappedComponent) { } componentWillUnmount () { this.clearAutoSaveTimeout(); - window.onbeforeunload = undefined; // eslint-disable-line no-undefined + // Cant unset the beforeunload because it might no longer belong to this component + // i.e. if another of this component has been mounted before this one gets unmounted + // which happens when going from project to editor view. + // window.onbeforeunload = undefined; // eslint-disable-line no-undefined } leavePageConfirm (e) { if (this.props.projectChanged) {